• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

求大神帮我注释一下这段代码!

(function($) {  
    var old = $.fn.drag;  
  
    function Drag(element, options) {  
        this.ver = '1.0';  
        this.$element = $(element);  
        this.options = $.extend({}, $.fn.drag.defaults, options);  
        this.init();  
               
    }  
  
    Drag.prototype = {  
        constructor: Drag,  
        init: function() {  
            var options = this.options;  
                          var ifDrag;
            this.$element.on('touchstart.drag.founder mousedown.drag.founder', function(e) {
                                ifDrag=true;   
                var ev = e.type == 'touchstart' ? e.originalEvent.touches[0] : e,  
                    startPos = $(this).position(),  
                    disX = ev.pageX - startPos.left,  
                    disY = ev.pageY - startPos.top,  
                    that = this;  
  
                //记录初始位置,以便复位使用  
                $(this).data('startPos', startPos);  
  
                if (options.before && $.isFunction(options.before)) {  
                    options.before.call(that, ev);  
                }  
  
                $(document).on('touchmove.drag.founder mousemove.drag.founder', function(e) {
                                        e.preventDefault();
                    var ev = e.type == 'touchmove' ? e.originalEvent.touches[0] : e,  
                        $this = $(that),  
                        $parent = $this.offsetParent(),  
                        $parent=$parent.is(':root')?$(window):$parent,  
                        pPos = $parent.offset(),  
                        pPos=pPos?pPos:{left:0,top:0},  
                        left = ev.pageX - disX - pPos.left,  
                        top = ev.pageY - disY - pPos.top,  
                        r = $parent.width() - $this.outerWidth(true),  
                        d = $parent.height() - $this.outerHeight(true);  
  
                    left = left < 0 ? 0 : left > r ? r : left;  
                    top = top < 0 ? 0 : top > d ? d : top;  
  
                    $(that).css({  
                        left: left + 'px',  
                        top: top + 'px'  
                    });  
  
                    if (options.process && $.isFunction(options.process)) {  
                        options.process.call(that, ev);  
                    }  
  
                    e.preventDefault();  
                });  
  
              $(document).on('touchend.drag.founder mouseup.drag.founder',
                          function(e) {  
        /*                                        if(isDrag){
                               
                                $(this).css({"top": "calc(50% - 60px)","left":"calc(50% - 60px)"});
               
                                }*/
                       
                                                e.preventDefault();       
                       
                    var ev = e.type == 'touchend' ? e.originalEvent.changedTouches[0] : e;  
  
                   if (options.end && $.isFunction(options.end)) {  
                        options.end.call(that, ev);  
                    }  
  
                    $(document).off('.drag.founder');
                                       
                                        }
                );  
                e.preventDefault();  
            });  
        }  
    };  
  
    //jQ插件模式  
   $.fn.drag = function(options) {  
        return this.each(function() {  
            var $this = $(this),  
                instance = $this.data('drag');  
  
            if (!instance) {  
                instance = new Drag(this, options);  
                $this.data('drag', instance);  
            } else {  
                instance.init();  
            }  
  
            if (typeof options === 'string') {  
                //instance.options[options].call(this);  
            }  
  
        });  
    };  
  
  $.fn.drag.defaults = {  
        before: $.noop,  
        process: $.noop,  
        end: $.noop  
    };  
  
    $.fn.drag.noConflict = function() {  
        $.fn.drag = old;  
        return this;  
    };
})(jQuery); // JavaScript Document

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

全部参与1

你用的是Java

使用道具 举报

发新帖

发布任务需求已有1031166位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!