User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 373,915 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,631 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting

scrolling images

Join Date: Dec 2004
Posts: 1,589
Reputation: tgreer is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 34
Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: scrolling images

  #2  
Apr 14th, 2005
Scrolling is tough... break this into steps. The first step is to write a "scrollDetector", a function that will report the positions, horizontal and vertical, that a user has scrolled.

IE and Moz browsers both store this value, but they use different JavaScript properties (the underlying DOM is different).

Once you can store the pixel values of the scroll, you can use them to position your image (or better yet, the <div> which contains your image).

For IE, use:

document.body.scrollTop

which is the number of pixels FROM the top the user has scrolled. How far right have they scrolled? document.body.scrollLeft

if the scrollbars don't exist on a particular page, the value returned will be zero.

Moz/Netscape/FireFox browsers use "window.pageYOffset" and "window.pageXOffset".

So you have to write 1) browser detection code and then 2) a function that will report pixels scrolled.

The next problem is, how/when do you call this function? Browsers may or may not have a "scroll" event, which may or may not fire on all elements, or may or may not fire if the scroll was done with the mousewheel vs. keyboard, etc. It's nasty.

So, I would use the setInterval() function. Call your scroll detector every so many milliseconds. Note the pixels scrolled, and use them to adjust your image position.

Lastly, load your setInterval() function in the body onload event.

It's a lot to put together, but it's straightforward coding.

Holler if you need more help.
Reply With Quote  
All times are GMT -4. The time now is 5:19 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC