[英]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/
希望有幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.