Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jun 2004
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    "scrollBy(0,-10)" within a div?

    hello folks-

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

    i have a scrollable div on this site. i already got help on how to scroll the div to the top with an internal link like:

    Code:
    <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?

    Code:
    <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
    Last edited by TheRoper; 06-25-2004 at 05:56 AM.

  • #2
    Regular Coder
    Join Date
    Jun 2004
    Location
    underground
    Posts
    186
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Here's one way...

    Code:
    <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>

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    It was me who made the smooth scrolling window 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.
    Code:
    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);
    }

  • #4
    New Coder
    Join Date
    Jun 2004
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks to you both! glenn, you're help doesn't go un-noticed... i recently nominated you in this thread

    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

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Actually I didn't post the link for you to acknowledge me.
    I know you already did in the poll. Thanks for the vote!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •