首页 > 移动平台 > 详细

jquery 如何判断鼠标向上向下移动

时间:2016-01-23 18:31:19      阅读:253      评论:0      收藏:0      [点我收藏+]

解决思路


当用户滚动指定的元素时,会发生 scroll 事件。

scroll 事件适用于所有可滚动的元素和 window 对象(浏览器窗口)。

scroll() 方法触发 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

jquery 如何判断鼠标向上向下移动

原文:http://11080466.blog.51cto.com/11070466/1737909

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!