Jquery mousemove事件仅在mousedown后更新一次
我在jquery中使用mousemove时遇到问题。我想在mousedown事件和mousemove事件之后检查鼠标指针的坐标,但它只更新一次,结果只是mousedown事件发生时的坐标 我真的需要一些建议,谢谢:) 我只在这里发布了我的原始代码的简短摘录: 另外,我尝试使用“$(document).ready(function(){”),但没有成功Jquery mousemove事件仅在mousedown后更新一次,jquery,mousemove,mousedown,Jquery,Mousemove,Mousedown,我在jquery中使用mousemove时遇到问题。我想在mousedown事件和mousemove事件之后检查鼠标指针的坐标,但它只更新一次,结果只是mousedown事件发生时的坐标 我真的需要一些建议,谢谢:) 我只在这里发布了我的原始代码的简短摘录: 另外,我尝试使用“$(document).ready(function(){”),但没有成功 <!DOCTYPE html> <head> <title>jQuery Test</title>
<!DOCTYPE html>
<head>
<title>jQuery Test</title>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript" language="javascript">
function my_func(event){
$("#log1").html("mouse is down");
var x = $(this);
//some code
$(document).ready(function(){
x.on("mousemove", function(){
$("#log1").html("x:"+event.pageX+" y:"+event.pageY);
});
});
}
$(document).ready(function(){
$("button").on("mousedown",my_func); //it needs to be a named function because I will call it multiple times
});
</script>
</head>
<body>
<button >TEST</button>
<div id="log1"></div>
</body>
</html>
jQuery测试
函数my_func(事件){
$(“#log1”).html(“鼠标按下”);
var x=$(此);
//一些代码
$(文档).ready(函数(){
x、 打开(“mousemove”,function(){
$(“#log1”).html(“x:+event.pageX+”y:+event.pageY);
});
});
}
$(文档).ready(函数(){
$(“button”).on(“mousedown”,my_func);//它需要是一个命名函数,因为我将多次调用它
});
试验
更改
x.on("mousemove", function(){
到
JSFIDLE->您是否忘记在鼠标移动功能上传递事件 试试这把小提琴
函数my_func(事件){
$(“#first”).html(“鼠标正在移动x:+event.pageX+”y:+event.pageY);
}
函数my_func1(事件){
$(“#first”).html(“鼠标现在放下了x:+event.pageX+”y:+event.pageY);
}
$(文档).ready(函数(){
$(“#first”)。on(“mousemove”,my#func);
美元(“#first”)。on(“mousedown”,my#func1);
});
首先澄清您的问题。非常感谢。我认为“myfunc”的事件参数足够了,但我错了。
x.on("mousemove", function(event){
function my_func(event) {
$("#first").html("mouse is moving</br>x:" + event.pageX + " y:" + event.pageY);
}
function my_func1(event) {
$("#first").html("mouse is now down</br>x:" + event.pageX + " y:" + event.pageY);
}
$(document).ready(function () {
$("#first").on("mousemove", my_func);
$("#first").on("mousedown", my_func1);
});