jquery鼠获取标滚轮次数(1)

来源:互联网 发布:2016年4月1日非农数据 编辑:程序博客网 时间:2024/06/01 15:24

这里使用了mousewheel的jquery插件。网址是:http://www.jq22.com/jquery-info805

功能描述:获取鼠标滚动次数。

所需要的引用的文件是:

1.jquery.min.js

2.jquery-mousewheel.js

结果图片:


html代码:

<!DOCTYPE html>
<html lang="zh-CN">
<meta http-equiv="Content-type" content="text/html" charset="utf-8" >
<head>
    <title>获取滚轮次数</title>
    <style>
    .box { width: 600px; height: 300px; background-color: #eed; }
    </style>
</head>
<body>
    <div class="box">
        <p>滚动鼠标为+1或者-1</p>
        <span>0</span>

    </div>
</body>
    <script type="text/javascript" src="script/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="script/jquery-mousewheel.js"></script>
    <script type="text/javascript" src="script/test.js"></script>
</html>


test.js代码:

$(function(){
    var len = 0;
    var $box = $('.box');
    var $text = $('.box span');
    $box.mousewheel(function(y){
         len += y;           
        if(y>0){
            //alert(len);
            $text.html(len);
        }else{
            $text.html(len);
        }
    });
});

       


0 0