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 10 of 10
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    94
    Thanks
    4
    Thanked 0 Times in 0 Posts

    this would be cool if i could get it working

    it scrolls smoothly to position but i need it to stop once it gets there.
    whats wrong with this code
    Code:
    function pageScroll() {
    if (document.body.scrollTop = '530'){ clearTimeout(scrolldelay); return;}
    
        	window.scrollBy(0,5); // horizontal and vertical scroll increments
      	scrolldelay = setTimeout('pageScroll()',15); // scrolls every 100 milliseconds
    
    }

  • #2
    New Coder
    Join Date
    Nov 2011
    Posts
    94
    Thanks
    4
    Thanked 0 Times in 0 Posts
    the problem is the if statement but i think im doing all of this wrong anyway

  • #3
    New Coder
    Join Date
    Nov 2011
    Posts
    94
    Thanks
    4
    Thanked 0 Times in 0 Posts
    yay i done it with a simple for loop.
    i feel silly now
    Code:
    <script type="text/javascript">
    function pageScroll() {
    for (i=1; i<530; i++){
    window.scrollBy(0,1);
    }
    
    }
    </script>

  • #4
    New Coder
    Join Date
    Nov 2011
    Posts
    94
    Thanks
    4
    Thanked 0 Times in 0 Posts
    works great on i.e and firefox but on my server there is no graphics accelirator so it takes about 30 seconds to reach the desire scroll height.
    is there a wau to check if there is an accelirator card and do an if statement on that

  • #5
    New Coder
    Join Date
    Nov 2011
    Posts
    94
    Thanks
    4
    Thanked 0 Times in 0 Posts
    i was wrong this does not work in firefox
    this just skips right down to the correct position but not smooth at all. when in ie it works lovely. could somebody give me a pointer please

    Code:
    <script type="text/javascript">
    function pageScroll() 
    {
    var speed2 =1;
    	for (i=0; i<531; i++)
    		{
    	var speed= 1;
    
    	if (a=10 && i<200){speed++;speed2=0;}
    	if (a=10 && i>201){speed--;speed2=0;}
    	if (speed<1){speed++;}
    	if (document.body.scrollTop >530){i=531;}
    
    	window.scrollBy(0,speed);
    	speed2++;
    		}
    
    }
    </script>

  • #6
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,502
    Thanks
    3
    Thanked 500 Times in 487 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    </head>
    
    <body>
    <input type="button" name="" value="ScrollTo 530" onmouseup="ScrollTo(530,1000);"/>
    <div style="height:2000px;" ></div>
    <script> vic=0; </script>
    <form name=Show id=Show style="position:absolute;visibility:visible;top:700px;left:0px;" >
    <input size=100 name=Show0 >
    </form>
    <script type="text/javascript">
    /*<![CDATA[*/
    
    function ScrollTo(to,ms) {
     var f=window.innerHeight?window.pageYOffset:document.documentElement.clientHeight?document.documentElement.scrollTop:document.body.scrollTop;
     clearTimeout(ScrollTo.dly);
     animate(f,to,new Date(),ms);
    }
    
    function animate(f,t,srt,mS){
     var ms=new Date().getTime()-srt,now=(t-f)/mS*ms+f;
     if (isFinite(now)){
      window.scrollTo(0,now);
     }
     if (ms<mS){
      ScrollTo.dly=setTimeout(function(){ animate(f,t,srt,mS); },10);
     }
     else {
      window.scrollTo(0,t);
     }
    }
    
    
    
    /*]]>*/
    </script>
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • Users who have thanked vwphillips for this post:

    gerble1000 (07-02-2012)

  • #7
    New Coder
    Join Date
    Nov 2011
    Posts
    94
    Thanks
    4
    Thanked 0 Times in 0 Posts
    brilliant thank you again

  • #8
    New Coder
    Join Date
    Nov 2011
    Posts
    94
    Thanks
    4
    Thanked 0 Times in 0 Posts
    i got the feeling that your code is supposed to slow down when it gets close to the target. but it keeps the same consistent speed. is there a way to make it act like an elivator stopping

  • #9
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,502
    Thanks
    3
    Thanked 500 Times in 487 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    </head>
    
    <body>
    <input type="button" name="" value="ScrollTo 530" onmouseup="ScrollTo(530,1000);"/>
    <div style="height:2000px;" ></div>
    <script> vic=0; </script>
    <form name=Show id=Show style="position:absolute;visibility:visible;top:700px;left:0px;" >
    <input size=100 name=Show0 >
    </form>
    <script type="text/javascript">
    /*<![CDATA[*/
    
    function ScrollTo(to,ms) {
     var f=window.innerHeight?window.pageYOffset:document.documentElement.clientHeight?document.documentElement.scrollTop:document.body.scrollTop;
     clearTimeout(ScrollTo.dly);
     animate(f,to,new Date(),ms,Math.PI/(2*ms));
    }
    
    function animate(f,t,srt,mS,i){
     var ms=new Date().getTime()-srt,now=(t-f)*Math.sin(i*ms)+f;
     if (isFinite(now)){
      window.scrollTo(0,now);
     }
     if (ms<mS){
      ScrollTo.dly=setTimeout(function(){ animate(f,t,srt,mS,i); },10);
     }
     else {
      window.scrollTo(0,t);
     }
    }
    
    
    
    
    
    /*]]>*/
    </script>
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • Users who have thanked vwphillips for this post:

    gerble1000 (07-03-2012)

  • #10
    New Coder
    Join Date
    Nov 2011
    Posts
    94
    Thanks
    4
    Thanked 0 Times in 0 Posts
    that is perfect
    nice and smooth


  •  

    Posting Permissions

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