mousemove事件仅在mousedown之后更新一次 [英] mousemove event updating only once after mousedown

查看:317
本文介绍了mousemove事件仅在mousedown之后更新一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在jquery中使用mousemove存在问题.我想在mousedown事件和mousemove事件之后检查鼠标指针的坐标,但是它仅更新一次,结果仅是mousedown事件发生时的坐标.

I'm having problems with mousemove in jquery. I want to check the coordinates of the mouse pointer AFTER a mousedown event AND a mousemove event, but it updates only once and the result is only the coordinates at the moment of the mousedown event.

我真的需要一些建议,谢谢:)

I really need some advices, thanks :)

我只在此处发布了我原始代码的一小段内容:

I post only a short extract of my original code here:

P.S.我尝试使用"$(document).ready(function(){",但没有成功.

P.S. I tried to use "$(document).ready(function(){", but without success.

<!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>

推荐答案

更改

x.on("mousemove", function(){

x.on("mousemove", function(event){

JsFiddle-> http://jsfiddle.net/6y83H/

JsFiddle -> http://jsfiddle.net/6y83H/

这篇关于mousemove事件仅在mousedown之后更新一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆