Scrolling Div Content.

N

Nalum

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.
 
W

Walton

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?
 
N

Nalum

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('"+div.id+"'))", 1);
 
W

Walton

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top