gpt4 book ai didi

javascript - 使用 jquery 1.8+ 绑定(bind)鼠标滚轮

转载 作者:太空宇宙 更新时间:2023-11-04 15:31:14 24 4
gpt4 key购买 nike

我在我的网站上使用 Jquery 1.8.3

我不能用这个 jquery 版本绑定(bind)鼠标滚轮,但是 1.4.2 版本可以成功绑定(bind)鼠标滚轮。

请给我一个解决这个问题的方案?

注意 :我只需要将鼠标滚轮绑定(bind)到 1.8+ 版本。因为其他插件都依赖于Jquery 1.8+

我的示例代码是:

<!DOCTYPE html>
<html>
<head>
<title>Mouse Wheel</title>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.4.2.js'></script>
<style type='text/css'>
body { text-align: center; }
#res
{
margin-top: 200px;
font-size: 128px;
font-weight: bold;
}
</style>
<script type='text/javascript'>
$(document).ready(function(){
var num = 0;
$(document).bind('mousewheel',function(e){
if (e.wheelDelta > 0)
{
$("#res").text(++num);
}
else
{
$("#res").text(--num);
}
});
});
</script>
</head>
<body>
<div id="res">0</div>
</body>
</html>

最佳答案

这是一个使用您的代码的工作示例,只需添加鼠标滚轮 javascript 插件:http://brandonaaron.net/code/mousewheel/demos

<!DOCTYPE html>
<html>
<head>
<title>Mouse Wheel</title>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.8.3.min.js'></script>
<script type='text/javascript' src='http://flexicontent.googlecode.com/svn-history/r1517/trunk/com_flexicontent_v2.x/site/librairies/fancybox/lib/jquery.mousewheel-3.0.6.pack.js'></script>
<style type='text/css'>
body { text-align: center; }
#res
{
margin-top: 200px;
font-size: 128px;
font-weight: bold;
}
</style>
<script type='text/javascript'>

jQuery(document).ready(function($){
var num = 0;
$(document).bind('mousewheel',function(e, delta){
if (delta > 0)
{
$("#res").text(++num);
}
else
{
$("#res").text(--num);
}
});
});
</script>
</head>
<body>
<div id="res">0</div>
</body>
</html>

关于javascript - 使用 jquery 1.8+ 绑定(bind)鼠标滚轮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13843533/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com