解决思路
当用户滚动指定的元素时,会发生 scroll 事件。
scroll 事件适用于所有可滚动的元素和 window 对象(浏览器窗口)。
scroll() 方法触发 scroll 事件,或规定当发生 scroll 事件时运行的函数。
$(selector).scroll()
<html> <head> <script type="text/javascript" src="j.js"></script> <script type="text/javascript"> x=0; $(document).ready(function(){ var initTop = 0; $(window).scroll(function(){ var scrollTop = $(document).scrollTop(); if(scrollTop > initTop){ alert("下"); } else { alert("上"); } initTop = scrollTop; }); //}); }); </script> </head> <body> <p>请试着滚动 DIV 中的文本:</p> <div style="width:200px;height:1000px;overflow:scroll;">text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. <br /><br /> text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text. text.</div> <p>滚动了 <span>0</span> 次。</p> </body>
</html>
本文出自 “11070466” 博客,请务必保留此出处http://11080466.blog.51cto.com/11070466/1737909
原文:http://11080466.blog.51cto.com/11070466/1737909