<script type="text/javascript"> window.onscroll = function(){ var t = document.documentElement.scrollTop || document.body.scrollTop; var oDiv = document.getElementById( "div" ); if( t >= 300 ) { //判断下拉距离 oDiv.style.display = "inline"; } else { oDiv.style.display = "none"; } } </script>
JQuery代码如下:
$(document).ready(function() {
$(window).scroll(function() {
if ($(document).scrollTop()<=0){
alert("滚动条已经到达顶部为0");
}
if ($(document).scrollTop() >= $(document).height() - $(window).height()) {
alert("滚动条已经到达底部为" + $(document).scrollTop());
}
});
});