当我在页面顶部时,我需要在 jQuery 中隐藏“Go-to Top” div 按钮。当我位于页面顶部时,该按钮出现,当我开始向下滚动页面时,我需要在滚动条到达顶部时隐藏该按钮并显示它。
这是我的代码,
$(function() {
var $elem = $('#content');
$('#nav_up').fadeIn('slow');
$('#nav_down').fadeIn('slow');
$(window).bind('scrollstart', function(){
$('#nav_up,#nav_down').stop().animate({'opacity':'0.2'});
});
$(window).bind('scrollstop', function(){
$('#nav_up,#nav_down').stop().animate({'opacity':'1'});
});
$('#nav_down').click(
function (e) {
$('html, body').animate({scrollDown: $elem.height()}, 800);
}
);
$('#nav_up').click(
function (e) {
$('html, body').animate({scrollTop: '0px'}, 800);
}
);
});