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 423,875 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 4,124 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
Views: 35450 | Replies: 9
Reply
Join Date: Feb 2005
Posts: 6
Reputation: stevenpowen is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
stevenpowen stevenpowen is offline Offline
Newbie Poster

scrolling images

  #1  
Apr 14th, 2005
Hi everyone:
How do I get an Image to scroll vertically down the Web page when the browser window scroll bar is moved. In other words, the image moves as the scolling browser window moves - up or down. thanks for your help.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Posts: 1,590
Reputation: tgreer is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 35
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  
Join Date: Feb 2005
Posts: 6
Reputation: stevenpowen is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
stevenpowen stevenpowen is offline Offline
Newbie Poster

Re: scrolling images

  #3  
Apr 15th, 2005
Originally Posted by tgreer
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.

Usually what I've done in the past is cut and paste and modify script to work. I'm not a programmer but I did stay in a Holiday Inn last night. Do you know of any snippets I could use just to get me going? Primarily it's IE that I will be writing for. Thanks for your help w/ this...
Reply With Quote  
Join Date: Dec 2004
Posts: 1,590
Reputation: tgreer is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 35
Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: scrolling images

  #4  
Apr 15th, 2005
I see... no, I don't know of any pre-existing code you could glean. But then, I haven't looked.

I could write you something, but I'm currently involved in a lot of "for pay" work, and don't have much time.

Why not just give it a try yourself? Everyone here would be glad to help you along.
Reply With Quote  
Join Date: Feb 2005
Posts: 6
Reputation: stevenpowen is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
stevenpowen stevenpowen is offline Offline
Newbie Poster

Re: scrolling images

  #5  
Apr 15th, 2005
Thanks, I'll do that
Reply With Quote  
Join Date: Dec 2004
Posts: 1,590
Reputation: tgreer is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 35
Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: scrolling images

  #6  
Apr 15th, 2005
Hold the presses!

Have you seen this site?

http://codepunk.hardwar.org.uk/ajs02.htm

It does exactly what I was describing. Plus, it's presented in a step by step tutorial fashion.
Reply With Quote  
Join Date: Feb 2005
Posts: 354
Reputation: DanceInstructor is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 12
DanceInstructor's Avatar
DanceInstructor DanceInstructor is offline Offline
Posting Whiz

Re: scrolling images

  #7  
Apr 15th, 2005
Codepunk's site isn't fancy or anything, but I find his tutorials very easy to follow and understand. Sorry for the slightly offtopic post
Clear Mind Hosting and Web Design

If I've helped you please consider adding to my reputation.
Reply With Quote  
Join Date: Dec 2005
Posts: 1
Reputation: jdmajor is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jdmajor jdmajor is offline Offline
Newbie Poster

Re: scrolling images

  #8  
Dec 5th, 2005
Originally Posted by stevenpowen
Hi everyone:
How do I get an Image to scroll vertically down the Web page when the browser window scroll bar is moved. In other words, the image moves as the scolling browser window moves - up or down. thanks for your help.

Check out the free scrolling images at
http://www.dynamicdrive.com/dynamicindex4/flyimage.htm

you will definitely enjoy the samples

jd
Reply With Quote  
Join Date: May 2006
Posts: 1
Reputation: lulubell is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
lulubell lulubell is offline Offline
Newbie Poster

Re: scrolling images

  #9  
May 23rd, 2006
hey yeah... that really made no sense to me... if you could just type out the html code with a sample picture and color codes or w/e for me... please and thank you.
Reply With Quote  
Join Date: Aug 2005
Posts: 4,782
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 319
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: scrolling images

  #10  
May 25th, 2006
Originally Posted by lulubell
hey yeah... that really made no sense to me... if you could just type out the html code with a sample picture and color codes or w/e for me... please and thank you.


This is really a horrendous idea. It looks awful and is annoying more than anything else. I wouldn't recommend doing it.
I'm not a programmer. My attitude starts with ignorance, holds steady at conversation, and ends with a trip to the hospital. Get used to it.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 4 (1 members and 3 guests)

abhaus

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 4:33 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC