$(document).scroll(function(){
var top=$(document).scrollTop();
if(top<300){
$('#to_top').hide();
}else{
$('#to_top').show();
}
})
其中“to_top”是“返回顶部”按钮的ID,
$(document).scroll(function(){}是滚动条移动时触发的事件
$(document).scrollTop()是监测滚动条距离页面顶部的距离
if判断条件中,当滚动条距离页面小于300px时,则不显示“返回顶部”,否则显示