By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,705 Members | 1,206 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,705 IT Pros & Developers. It's quick & easy.

Scrolling Div Content.

P: n/a
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
Share this Question
Share on Google+
3 Replies

P: n/a
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

P: n/a
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

P: n/a
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.