javascript - 这段代码为什么mousemove事件没法解除
ringa_lee
ringa_lee 2017-04-11 11:24:02
[JavaScript讨论组]
<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <script src="jquery.min.js" type="text/javascript"></script>
  <title>Document</title>
  <style>
        .d1{width:100px;height:100px;background:red;}
        .d2{width:100px;height:100px;background:blue;}
  </style>
 </head>
 <body>
  <p class="d1">hello</p>

  <p class="d2">world</p>
 </body>
 <script>
    $('.d1').on('mousedown',function(){
        var e = window.event||arguments[0];
        var posx = $('.d2').offset().left;
        var posY = $('.d2').offset().top;
        $(document).bind('mousemove',function(){
            var e = window.event||arguments[0];
            var npx = e.clientX - posx;
            var npy = e.clientY - posY;
            $('.d2').css({'top':(npy +'px'),'left':(npx +'px'),'position':'absolute'})
        })
        $(document).bind('mouseup',function(){
            $('document').unbind('mousemove');
            $('document').unbind('mouseup');
        })
    })
    
 </script>
</html>
ringa_lee
ringa_lee

ringa_lee

全部回复(1)
阿神
$(document).unbind('mousemove');
$(document).unbind('mouseup');

document不要用引号

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号