window.onscroll = function () {
var t = document.documentElement.scrollTop || document.body.scrollTop;
if (t > 0) {
$(".cbbfixed").css("bottom", "10px");
} else {
$(".cbbfixed").css("bottom", "-85px");
}
}
t:滚动条距离top端的距离
t>0,即滚动条一旦滚动,立即执行if()语句,else()中的代码是,滚动条到到top处时,返回顶部的div隐藏
返回顶部按钮的点击操作:
$("#cgotop").click(function(){
$('body,html').animate({ scrollTop: 0 }, 100);
return false;
});
//codego.net/3/1/1/监听某个元素的滚动条事件
$(selector).scroll(function(){.......});
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30011186/viewspace-1420602/
,如需转载,请注明出处,否则将追究法律责任。