...

View Full Version : "scrollBy(0,-10)" within a div?



TheRoper
06-25-2004, 06:20 AM
hello folks-

all of my questions lately seem to be about roughly the same thing... :rolleyes:

i have a scrollable div on this site (http://www.charityadvantage.com/familiesintransitionsantacruz/images/mock2.htm). i already got help on how to scroll the div to the top with an internal link like:


<a href='#' onclick="document.all['layerName'].scrollTop = 0;return false">top</a>

on a recent project, i learned about being able to scroll smoothly to the top, as opposed to just jumping to the top. My question is why doesn't this work?



<HTML>
<HEAD>
<SCRIPT LANGUAGE="javascript" TYPE="text/javascript"><!--

var top_t;
function top() {
if (document.all['content'].scrollTop!=0){
document.all['content'].scrollBy(0,-10);
top_t=setTimeout('top()',10);
}
else clearTimeout(top_t);
}

//--></SCRIPT>
</HEAD>

<BODY>
<DIV id="content">Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text. Space filler text.
<a href="#" onClick="top();return false">top</a>
</DIV>
</BODY>


the error i get is: "object does not support this property or method" so can i simply not use "scrollBy" within a div... if so, are there any suggestions?
thanks :cool:

neofibril
06-25-2004, 08:46 AM
<html>
<head>
<script type="text/javascript">
function slowTop()
{
var el = document.getElementById("content"),
st = el.scrollTop;
go();
function go()
{
st = st - 10;
if(st > -1)
{
el.scrollTop = st;
setTimeout(go, 10);
}
else
el.scrollTop = 0;
}
}
</script>
<style type="text/css">
#content
{
width:706px;
height:402px;
overflow:auto;
text-align:center;
background:#f4f4f4;
padding:1px 4px 1px 4px;
border:1px solid #000066;
}
</style>
</head>
<body>
<div id="content">
<blockquote>
<p align="justify"><br>
&nbsp;&nbsp;&nbsp;&nbsp; In most cases Families In Transition provides a
short-term housing subsidy to families in scattered sites throughout the
community. The goal is for the family to obtain necessary rental assistance and
social services tailored to their individual circumstances while living in
stable, private market housing that they will be able to maintain on their own
at the completion of Families in Transition services.<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; Since 1992 Families In Transition has been preventing and ending
homelessness for local families with children. Over one thousand families have
received services that have enabled them to provide a home and greater stability
for their children.</p>
<p align="justify">&nbsp;&nbsp;&nbsp;&nbsp; In most cases Families In Transition provides a
short-term housing subsidy to families in scattered sites throughout the
community. The goal is for the family to obtain necessary rental assistance and
social services tailored to their individual circumstances while living in
stable, private market housing that they will be able to maintain on their own
at the completion of Families in Transition services.<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; Since 1992 Families In Transition has been preventing and ending
homelessness for local families with children. Over one thousand families have
received services that have enabled them to provide a home and greater stability
for their children.</p>
<p align="justify">&nbsp;&nbsp;&nbsp;&nbsp; In most cases Families In Transition provides a
short-term housing subsidy to families in scattered sites throughout the
community. The goal is for the family to obtain necessary rental assistance and
social services tailored to their individual circumstances while living in
stable, private market housing that they will be able to maintain on their own
at the completion of Families in Transition services.<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; Since 1992 Families In Transition has been preventing and ending
homelessness for local families with children. Over one thousand families have
received services that have enabled them to provide a home and greater stability
for their children.<p align="justify">&nbsp;&nbsp;&nbsp;&nbsp; In most cases Families In Transition provides a
short-term housing subsidy to families in scattered sites throughout the
community. The goal is for the family to obtain necessary rental assistance and
social services tailored to their individual circumstances while living in
stable, private market housing that they will be able to maintain on their own
at the completion of Families in Transition services.<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; Since 1992 Families In Transition has been preventing and ending
homelessness for local families with children. Over one thousand families have
received services that have enabled them to provide a home and greater stability
for their children.<p align="justify">&nbsp;&nbsp;&nbsp;&nbsp; In most cases Families In Transition provides a
short-term housing subsidy to families in scattered sites throughout the
community. The goal is for the family to obtain necessary rental assistance and
social services tailored to their individual circumstances while living in
stable, private market housing that they will be able to maintain on their own
at the completion of Families in Transition services.<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; Since 1992 Families In Transition has been preventing and ending
homelessness for local families with children. Over one thousand families have
received services that have enabled them to provide a home and greater stability
for their children.<p><a href="#" onclick="slowTop();return false">top</a>
</blockquote>
</div>
</body>
</html>

glenngv
06-25-2004, 09:00 AM
It was me who made the smooth scrolling window (http://www.codingforums.com/showthread.php?t=39936#post209187) for you. :)
Here's the one for the div.
neofibril beat me to it but I'll post it anyway. I was coding it when he posted his. This is shorter.


var t;
function scrollDivToTop(){
var div = document.getElementById('theDiv');
if (div.scrollTop>0){
div.scrollTop--; //scroll 1 pixel up
t = setTimeout('scrollDivToTop()', 10);
}
else clearTimeout(t);
}

TheRoper
06-25-2004, 09:16 AM
thanks to you both! glenn, you're help doesn't go un-noticed... i recently nominated you in this thread (http://www.codingforums.com/showthread.php?p=212632#post212632) :thumbsup:

i just tried out neofibril's script and it works just fine, so i'll probably just stick with it...

again, thank you both... take care :)

glenngv
06-25-2004, 09:41 AM
Actually I didn't post the link for you to acknowledge me. :)
I know you already did in the poll. Thanks for the vote! :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum