Move a DIV using JavaScript on scrolling?

23rd of January 2014 0

Move a DIV using JavaScript on scrolling?

I want to transfer the value of .scrolltop to the left attribute on a div, so when I scroll the window, the div would move left or right depending on the current value of scrollTop.
I have no idea of who to write this!

“Just got me a javascript book yesterday”

Best answer:

Answer by Teoma
If you give the DIV an ID then you can reference it in javascript using:

var theDiv = document.getElementById(‘divIDname’); = ’10px’; // would set the DIVs position 10 pixels from the left

There’s tons of things you can then do with it’s attributes and CSS styling.

The easiest way I found to animate DIVs is to use jQuery, follow a few simple tutorials on it and it’s very simple, but do read that book first ☺ ( )

What do you think? Answer below!

Filed under § jquery animate — Tagged with , , ,

Share it!

Was it good for you to?


Support for the site!

No sponsors at the moment.

Your opinion matters. Add it below.

Tip: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Recent comments


Copyright since 2010. All rights reserved. Design and the Absolute Theme by Tommie Hansen.