使用 jQuery 检测鼠标速度
Detect mouse speed using jQuery
我想检测鼠标速度,例如,仅当检测到的数字大于 5 时才会触发事件
我发现了一个我认为类似的例子:http://www.loganfranken.com/blog/49/capturing-cursor-speed/
但是我无法让它看到div 内部的数字并根据结果数字触发事件,这是我的尝试:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="jquery.cursometer.1.0.0.min.js"></script>
<script>
$(function() {
var $speedometer = $('#speedometer');
$('#test-area').cursometer({
onUpdateSpeed: function(speed) {
$speedometer.text(speed);
},
updateSpeedRate: 20
});
$("#test-area").mouseover(function(){
if(this.value > 5) {
console.log("asdasd");
}
else {
console.log("bbb");
}
})
});
</script>
<style>
#test-area
{
background-color: #CCC;
height: 300px;
}
</style>
</head>
<body>
<div id="test-area"></div>
<div id="speedometer"></div>
</body>
</html>
(我是导致这里麻烦的插件的作者)
该示例不起作用,因为this.value
不是指速度(它是undefined
)。下面是示例的更新版本:http://jsfiddle.net/eY6Z9/
速度值存储在变量中比存储在 HTML 元素的文本值中可能更有效。以下是具有该增强功能的更新版本:http://jsfiddle.net/eY6Z9/2/
希望对您有所帮助!
相关文章:
- EaseJS拖放;放下(动画CC)电影剪辑的鼠标坐标
- 即使光标位于屏幕边缘,也可以跟踪鼠标速度
- CSS使用鼠标使许多背景以不同的速度移动
- 使用鼠标滚轮jquery插件的滚动速度
- Cursometer - 呈现用户的鼠标速度
- 鼠标速度 JavaScript 函数
- 使用 jQuery 检测鼠标速度
- 鼠标移动速度比工具提示快
- 更改 animate() 速度,同时将其动画化并将鼠标悬停在元素上
- 有没有办法在鼠标悬停时设置转换速度
- 准确计算鼠标速度
- 使用JavaScript计算鼠标滚轮滚动速度
- 当用户将鼠标悬停在图像上时,使图像加载速度尽可能快
- 弹性滑块和鼠标轮速度
- 当鼠标按下时,首先缓慢减少数量,然后增加下降速度(jQuery)
- 鼠标瞬间速度在javascript
- 我们可以只测量垂直鼠标速度使用光标计
- 改变鼠标滚动时滚动条的速度
- 降低鼠标速度
- 使用JS跟踪鼠标速度