PDA

View Full Version : Can't figure out a way to auto-scroll to a certain point within a div.



DayOldPorridge
10-26-2008, 03:22 AM
I'm not quite sure how I would go about doing this. I've searched for ways to scroll to a point within a div, but I've only been able to find methods for doing this within the window (and not the div).

Does anyone know how to auto-scroll to a certain point within a div? And when I say auto-scroll, I mean like smooth scrolling.

Here's the code I have right now. I just don't know what to add to it.



<script type="text/javascript">

var t;
var doLoop = true;

function scrollDivToTop(divid)
{
var div = document.getElementById(divid);

if (div.scrollTop>0 && doLoop)
{
div.scrollTop-=3;
t = setTimeout("scrollDivToTop('" + divid + "')", 1);
}
else clearTimeout(t);
}

function scrollDivToBottom(divid)
{

var div = document.getElementById(divid);

if (div.scrollTop<999999999 && doLoop)
{
div.scrollTop+=3;
t = setTimeout("scrollDivToBottom('" + divid + "')", 1);
}
else clearTimeout(t);
}

function stop()
{
doLoop = false;
setTimeout('doLoop = true;', 5);
}

</script>

magicyte
10-26-2008, 03:39 AM
Stuff (http://www.daniweb.com/forums/thread30994.html)

^ This ^ May ^ Help ^

-magicyte

DayOldPorridge
10-26-2008, 04:31 AM
Stuff (http://www.daniweb.com/forums/thread30994.html)

^ This ^ May ^ Help ^

-magicyte

I've read that thread already, but that one line of code doesn't seem so straightforward. ;P

I think I need something like this:



<script type="text/javascript">
var scrollExample = new Fx.Scroll($('content'));
scrollExample.start(0, 120);
</script>

But then, to activate it, could I just do onClick?



<a onclick="scrollExample.start();">scroll</a>

I've actually tried this already (and yes, I have the correct div ID), but I've probably got the onclick part wrong.

DayOldPorridge
10-26-2008, 05:35 AM
Nevermind, I found a more simple solution:

http://scripterlative.com?softdivscroll

No need for onClick scripts. ;P