470,863 Members | 1,276 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,863 developers. It's quick & easy.

Scrolling Div Content.

Hey all,
I'm trying to scroll the content of a div tag up and down.
I've gotten that to work but, I need it to keep scrolling while the
mouse is over the image.
This is the code that I have at the moment.

function scrollUp(div)
{
// we first have to get the position of the div.
var topOfDiv = div.scrollTop;
var heightOfDiv = div.scrollHeight;

// now we have to check that the div when scrolling up doesn't scroll
past the top.
if(topOfDiv 0)
{
div.scrollTop = div.scrollTop - (div.scrollAmount = 8);
setTimeout(scrollUp(div), 1); <-- this is where I'm having trouble.
}
}

I can't get the setTimeout to work with the scrollUp argument.
I'm trying to get it to scroll up the content of the div slowly so
that it is a visible process and doesn't just jump from end to end.
which it does at the moment.

Feb 9 '07 #1
3 10226
On Feb 9, 7:09 am, "Nalum" <mallon.l...@gmail.comwrote:
Hey all,
I'm trying to scroll the content of a div tag up and down.
I've gotten that to work but, I need it to keep scrolling while the
mouse is over the image.
This is the code that I have at the moment.

function scrollUp(div)
{
// we first have to get the position of the div.
var topOfDiv = div.scrollTop;
var heightOfDiv = div.scrollHeight;

// now we have to check that the div when scrolling up doesn't scroll
past the top.
if(topOfDiv 0)
{
div.scrollTop = div.scrollTop - (div.scrollAmount = 8);
setTimeout(scrollUp(div), 1); <-- this is where I'm having trouble.
}

}

I can't get the setTimeout to work with the scrollUp argument.
I'm trying to get it to scroll up the content of the div slowly so
that it is a visible process and doesn't just jump from end to end.
which it does at the moment.

setTimeout(scrollUp(div), 1); is incorrect. you can't pass your
function call a parameter in this case - scrollUp(div).
setTimeout should be called like this: setTimeout(function,
milliseconds)
you have it like this setTimeout(function call, milliseconds)
try wrapping that call inside a function instead:

setTimeout(function() {scrollUp(div)}, 1);

does that do it?

Feb 9 '07 #2
On Feb 9, 3:23 pm, "Walton" <jrhol...@gmail.comwrote:
On Feb 9, 7:09 am, "Nalum" <mallon.l...@gmail.comwrote:
Hey all,
I'm trying to scroll the content of a div tag up and down.
I've gotten that to work but, I need it to keep scrolling while the
mouse is over the image.
This is the code that I have at the moment.
function scrollUp(div)
{
// we first have to get the position of the div.
var topOfDiv = div.scrollTop;
var heightOfDiv = div.scrollHeight;
// now we have to check that the div when scrolling up doesn't scroll
past the top.
if(topOfDiv 0)
{
div.scrollTop = div.scrollTop - (div.scrollAmount = 8);
setTimeout(scrollUp(div), 1); <-- this is where I'm having trouble.
}
}
I can't get the setTimeout to work with the scrollUp argument.
I'm trying to get it to scroll up the content of the div slowly so
that it is a visible process and doesn't just jump from end to end.
which it does at the moment.

setTimeout(scrollUp(div), 1); is incorrect. you can't pass your
function call a parameter in this case - scrollUp(div).

setTimeout should be called like this: setTimeout(function,
milliseconds)
you have it like this setTimeout(function call, milliseconds)

try wrapping that call inside a function instead:

setTimeout(function() {scrollUp(div)}, 1);

does that do it?
Thanks for your reply.
I figured out a way to do it a little bit before you replied to this.
Though I will check what you have told me.
Below is how I got it to work.

setTimeout("scrollUp(document.getElementById('"+di v.id+"'))", 1);

Feb 9 '07 #3
setTimeout("scrollUp(document.getElementById('"+di v.id+"'))", 1);

oh yes! putting the function call in quotes works as well. not as
graceful in my opinion though ;-)

Feb 9 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Cat Laugel | last post: by
4 posts views Thread by mr_burns | last post: by
4 posts views Thread by headware | last post: by
9 posts views Thread by Mark Horrell | last post: by
2 posts views Thread by Fabrizio | last post: by
7 posts views Thread by seven.reeds | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.