原生javascript实现DIV拖拽并计算重复面积(2)

var slice = Array.prototype.slice;
window.Bind = function(object, fun) {
    var args = slice.call(arguments).slice(2);
    return function() {
            return fun.apply(object, args);
    };
};
window.BindAsEventListener = function(object, fun,args) {
    var args = slice.call(arguments).slice(2);
    return function(event) {
        return fun.apply(object, [event || window.event].concat(args));
    }
};
//copy from jQ
window.extend = function(){
    var target = arguments[0] || {}, i = 1, length = arguments.length, deep = true, options;
    if ( typeof target === "boolean" ) {
        deep = target;
        target = arguments[1] || {};
        i = 2;
    }
    if ( typeof target !== "object" && Object.prototype.toString.call(target)!="[object Function]")
        target = {};
    for(;i<length;i++){
        if ( (options = arguments[ i ]) != null )
            for(var name in options){
                var src = target[ name ], copy = options[ name ];
                if ( target === copy )
                    continue;
                if ( deep && copy && typeof copy === "object" && !copy.nodeType ){
                    target[ name ] = arguments.callee( deep, src || ( copy.length != null ? [ ] : { } ), copy );
                }   
                else if(copy !== undefined)
                    target[ name ] = copy;                       
            }
    }
    return target;           
};
//copy from jQ
window.each =  function ( object, callback, args ) {  
    var name, i = 0, length = object.length;  
    if ( args ) {
  args = Array.prototype.slice.call(arguments).slice(2);
        if ( length === undefined ) {  
            for ( name in object )  
                if ( callback.apply( object[ name ],[name,object[ name ]].concat(args) ) === false )  
                    break;  
        } else 
            for ( ; i < length; i++)  
                if ( callback.apply( object[ i ],[i,object[ i ]].concat(args)) === false )   //
                    break;  
    } else {     
        if ( length === undefined ) {  
            for ( name in object )  
                if ( callback.call( object[ name ], name, object[ name ] ) === false )  
                    break;  
        } else 
            for ( var value = object[0];  
                i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}  
    }  
    return object;  
};  
window.currentStyle = function(element){
    return element.currentStyle || document.defaultView.getComputedStyle(element, null);
};
window.objPos = function(elem){
    var left = 0, top = 0, right = 0, bottom = 0,doc = elem ? elem.ownerDocument : document;
    if ( !elem.getBoundingClientRect || window.Sys.ie8 ) {
        var n = elem;
        while (n) { left += n.offsetLeft, top += n.offsetTop; n = n.offsetParent; };
        right = left + elem.offsetWidth; bottom = top + elem.offsetHeight;
    } else {
        var rect = elem.getBoundingClientRect();
        left = right = doc.documentElement.scrollLeft || doc.body.scrollLeft;
        top = bottom = doc.documentElement.scrollLeft || doc.body.scrollLeft;
        left += rect.left; right += rect.right;
        top += rect.top; bottom += rect.bottom;
    }
    return { "left": left, "top": top, "right": right, "bottom": bottom };       
};
window.hasClass = function(element, className){
    return element.className.match(new RegExp('(\\s|^)'+className+'(\\s|$)'));
};
window.addClass = function(element, className){
    !window.hasClass(element, className)&&(element.className += " "+className);
};
window.removeClass = function(element, className){
    window.hasClass(element, className)&&(element.className = element.className.replace(new RegExp('(\\s|^)'+className+'(\\s|$)'),' '));
}
})(window);

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgxdyd.html