smooth scrolling of div element

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tromton
    New Member
    • Dec 2007
    • 8

    smooth scrolling of div element

    heello,

    i havee one div element in my site with several anchors, that i link to.
    to change from anchor to another id like to have a smooth scrolling effect.
    all the smooth scrolling effects i could finde onlinee where to generall change all the links on the webpage and where quite overloaded. so i trieed to do something on my own. ther ist no error coming from firefox, but it doesent work also. maybe someonee can help me with this.
    heres the function ive written:
    Code:
    function smoothScrolling(ScrollElement,AnchorElement)
    {
    	var x = 5;
    	var SE = document.getElementById(ScrollElement).scrollTop;
    	var AE = document.getElementById(AnchorElement).offsetTop;
    	
    	if(SE > AE)
    		for(i=SE;i<=(AE-8);i=i+1)
    		{
    			setTimeout("SE = i;",x);
    			x = x+5;
    		}
    	else
    		for(i=SE;i>=(AE-8);i=i-1)
    		{
    			setTimeout("SE = i;",x);
    			x = x+5;
    		}
    }
    so actually its only a loop with a increasing timout setting in positioning the site one point by another towards the new anchor.

    if anybody has a idea, what the problem about theis code, please let me know - that would be great.

    all the best
    trom
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    You're only setting the variable SE, not the actual scrollTop property.

    Comment

    Working...