user970727 user970727 - 5 months ago 317x
Javascript Question

jQuery - ScrollTop without animation

How can I use the scrolltop without an animation

This code works:

var offTop = $('#box').offset().top;
offTop = offTop-43;
$('#mainCt').animate({scrollTop: '+=' + offTop + 'px'}, 400);

And here are my (not working solutions):

$("#mainCt").scrollTop('+=' + offTop + 'px'); // doesn't work
$("#mainCt").scrollTop('+='+offTop); // doesn't work
hhh = setTimeout(' $("#mainCt").scrollTop('+offTop+');',800); // doesn't work



maybe if you don't want an animation or anything fancy just use an anchor

<a name="top"></a>

Place it where you need to scroll

and in your function where you are calling use


You could also create a function to append the anchor before the element, do the document.location thing and later remove that anchor.