www.webdeveloper.com
Results 1 to 5 of 5

Thread: scroll to a particular direction

  1. #1
    Join Date
    Nov 2013
    Posts
    44

    scroll to a particular direction

    i want to scroll my window to a certain point and i want a smooth scroll.But i dont know why this code isn't working.can any one explain to me the reasons behind it?
    Code:
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Untitled Document</title>
    <style>
    .this{
    	width:200px;
    	height:1000px;
    	border:1px solid black;
    }
    
    
    </style>
    
    </head>
    
    <body>
    <a href="#" onClick="return false;" onMouseDown="scroll('div1');">click to div1</a></br>
    <a href="#" onClick="return false;" onMouseDown="scroll('div2');">click to div2</a></br>
    <a href="#" onClick="return false;" onMouseDown="scroll('div3');">click to div3</a></br>
    <a href="#" onClick="return false;" onMouseDown="scroll('div4');">click to div4</a></br>
    <div class="this" id="div1">div1</div>
    <a href="#" onClick="return false;" onMouseDown="toTop();">back to top</a>
    <div class="this" id="div2" >div2</div>
    <a href="#" onClick="return false;" onMouseDown="toTop();">back to top</a>
    <div class="this"id="div3" >div3</div>
    <a href="#" onClick="return false;" onMouseDown="toTop();">back to top</a>
    <div class="this" id="div4" >div4</div>
    <a href="#" onClick="return false;" onMouseDown="toTop();">back to top</a>
    <script>
    function scroll(el){
    	var m=document.getElementById(el);
    	var t=m.offsetTop;
    		var c=window.pageYOffset;
    	window.scrollBy(0,40);
    		if(c==t){
    			clearTimeout(p);
    		}
    
    		var p=setTimeout(scrolll,50);
    		
    	
    }
    
    </script>
    <script>
    function toTop(){
    	var m=window.pageYOffset;
    	window.scrollBy(0,-m);
    }
    </script>
    </body>
    </html>

  2. #2
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by alzami View Post
    i want to scroll my window to a certain point and i want a smooth scroll.But i dont know why this code isn't working.can any one explain to me the reasons behind it?
    There is at least one syntax error. You can't expect to develop a script without using the error console.

  3. #3
    Join Date
    Nov 2013
    Posts
    44
    what do you mean?still cant find the problem.i even cant see any error here??

  4. #4
    Join Date
    Nov 2013
    Posts
    44
    this script also not working
    <script>
    var i=0;
    function scroll(el){
    var m=document.getElementById(el);
    var t=m.offsetTop;
    var c=window.pageYOffset;
    for(i=0;i<=m.offsetTop;i++){
    window.scrollBy(0,i);

    }




    }

    </script>

  5. #5
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by alzami View Post
    what do you mean?still cant find the problem.i even cant see any error here??
    Code:
    var p=setTimeout(scrolll,50);
    Use the error console: Ctrl+Shift+J in Firefox.

    There are scripts available to do this, which require no configuration.
    Last edited by Logic Ali; 11-28-2013 at 10:39 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles