I have this code to make page scroll up and down,Please tell me how to make it back to scroll postion instead of down page when i click down?
<a href="javascript://" id="toDown">Down</a>
<a href="javascript://" id="toTop">Top</a>
<script type="text/javascript">
jQuery.noConflict();
$(window).scroll(function(){
if($(window).scrollTop() > "0"){
$('#toTop').fadeIn();
$('#toDown').hide();
}else if($(window).scrollTop() == "0"){
$('#toTop').fadeOut();
$('#toDown').fadeIn();
}
});
$('#toTop').click(function(){
$('html, body').animate({scrollTop:0}, 0);
$('#toDown').fadeIn();
});
$('#toDown').click(function(){
$('html, body').animate({$('body').height()}, 0);
$('#toDown').fadeOut();
});
</script>
Add a variable to store the scroll position at the moment ‘top’ is clicked:
If ‘top’ is clicked, save the current scroll position:
If ‘down’ is clicked, check if a scroll position has been stored; if yes, move to this position, otherwise move the the end of the document:
The complete source code:
Also see this jsfiddle.