账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    写个拖拽插件没有报错但是为什么拖动不了
    29
    0

    写个拖拽插件没有报错但是为什么拖动不了

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    <style>

    div1 {width: 100px; height: 100px; background: red; position: absolute;}

    img1 { position: absolute;}

    </style>

    </head>

    <body>

    <div id="div1"></div>
    <img src="1.jpg" id="img1" />
    

    <script>

    (function(window){

         var Drog = function(config){
            this._init(config);
         };
    
        Drog.prototype = {
            _init:function(config){
               // 使其指向 Drog
                initEvents.call(this,config);
                this.move(config)
            },
              move:function(obj) {
                // console.log(typeof this.obj)
                   var obj =  this.obj;
                 obj.onmousedown = (ev) => {
                        var ev = ev || event;
    
                        var disX = ev.clientX - this.offsetLeft;
                        var disY = ev.clientY - this.offsetTop;
    
                        if ( obj.setCapture ) {
                        obj.setCapture();
                        }
                   document.onmousemove = (ev) => {
                        var ev = ev || event;
    
                        var L = ev.clientX - disX;
                        var T = ev.clientY - disY;
    
                        if ( L < 0 ) {
                        L = 0;
                        } else if ( L > document.documentElement.clientWidth - obj.offsetWidth ) {
                        L = document.documentElement.clientWidth - obj.offsetWidth;
                        }
    
                        if ( T < 0 ) {
                        T = 0;
                        } else if ( T > document.documentElement.clientHeight - obj.offsetHeight ) {
                        T = document.documentElement.clientHeight - obj.offsetHeight;
                        }
                        obj.style.left = L + 'px';
                        obj.style.top = T + 'px';
                        }
                document.onmouseup = function() {
                        document.onmousemove = document.onmouseup = null;
                        if ( obj.releaseCapture ) {
                        obj.releaseCapture();
                        }
                }
    
                return false;
            }
    
          }  
           
      };
       var initEvents = function(config){
             this.obj = document.getElementById(config.oDiv)
                // console.log(typeof this.obj)
          };
    
    window.Drog = Drog;
    

    })(window)

        var p = new Drog(
            {
             oDiv:'div1'
            }
          )
               
    

    </script>
    </body>
    </html>

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 瞳孔里的泪 普通会员 1楼

      拖拽插件的运行过程中如果报错,可能是由于以下原因导致的:

      1. 插件未成功安装:请确保您已经正确安装了该插件。您可以使用插件管理器或者插件开发工具来查看和安装插件。

      2. 插件依赖问题:请确保您的系统已经安装了所有必要的依赖库。您可以通过在插件管理器中查看依赖库版本来确定是否存在依赖缺失的问题。

      3. 插件版本问题:请确保您使用的插件版本与您的系统版本兼容。您可以通过插件管理器查看当前版本的插件,或者通过查看插件的文档来了解版本要求。

      4. 插件权限问题:请确保您有足够的权限来使用插件。插件的使用需要您的系统权限,您可以尝试右键点击插件图标,然后选择“以管理员身份运行”来解决权限问题。

      5. 插件兼容性问题:请确保您的系统已经支持该插件。您可以尝试在不同的系统环境中测试插件,或者查看插件的开发者网站来了解插件的兼容性要求。

      如果您无法确定问题的原因,建议您查阅插件的文档或者寻求插件开发者的帮助。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部