window.onscroll页面滚动条滚动事件
用途一:"返回顶部";
window.onscroll = function(){ var t = document.documentElement.scrollTop || document.body.scrollTop; var top_div = document.getElementById( "top_div" ); if( t >= 300 ) { top_div.style.display = "inline"; } else { top_div.style.display = "none"; } }
用途二:"商品详情菜单漂浮" 当鼠标滚动到一定位置 会有一个导航漂浮起来
window.onscroll = function(){ var t = document.documentElement.scrollTop || document.body.scrollTop; var Div = document.getElementById( "fix_goods" ); if( t <= 755 ) { Div.style.position = ""; Div.style.top = ""; } else { //Div.style.display = "none"; Div.style.position = "fixed"; Div.style.top = "-10px"; } }
原文来源:http://www.cnblogs.com/wesky/admin/EditPosts.aspx?postid=3303694&update=1