zoukankan      html  css  js  c++  java
  • jquery实现点击空白的事件

    //点击空白扩展
    jQuery.fn.extend({
        clickOther: 
    function() {
            
    if (window.click_other == null) {
                window.click_other 
    = new Array();
            }
            window.click_other.push({ target: 
    this, func: arguments[0] });
            $(document.body).click(
    function(e) {
                
    for (var i = 0; i < click_other.length; i++) {
                    
    var item = window.click_other[i];
                    
    var target = item.target;
                    
    if (typeof (target) == "String") target = $(target)[0];

                    
    if (e.target == target) {
                        
    continue;
                    }
                    
    var index = $(e.target).parents().index(target);
                    
    if (index == -1) {
                        item.func();
                    }
                }
            });

        },
        unClickOther: 
    function() {
            
    if (window.click_other == null) {
                
    return;
            }
            
    for (var i = 0; i < window.click_other.length; i++) {
                
    var item = window.click_other[i];
                
    if (item.target == this) {
                    window.click_other.splice(i, 
    1);
                }
            }
        }
    }); 
    //点击空白扩展
    jQuery.fn.extend({
        clickOther: 
    function() {
            
    function isInside(e, target) {
                
    var x = e.pageX;
                
    var y = e.pageY;
                
    var left = target.offset().left;
                
    var width = target.width();
                
    var top = target.offset().top;
                
    var height = target.height();

                
    if (x > left && x < left + width && y > top && y < top + height) return true;
                
    return false;
            }
            
    if (window.click_other == null) {
                window.click_other 
    = new Array();
            }
            
    this.except = null;
            
    var func = arguments[0];
            
    if (typeof (func) == "string") {
                
    this.except = document.getElementById(func);
                func 
    = arguments[1];
            }
            window.click_other.push({ target: 
    this, func: func });
            $(document).click(
    function(e) {
                
    for (var i = 0; i < click_other.length; i++) {
                    
    var item = window.click_other[i];
                    
    var target = $(item.target);
                    
    if (isInside(e, target)) continue;
                    
    if (item.target.except) {
                        
    var except = $(item.target.except);
                        
    if (isInside(e, except)) continue;
                    }
                    item.func();
                }
            });

        },
        unclickOther: 
    function() {
            
    if (window.click_other == null) {
                
    return;
            }
            
    for (var i = 0; i < window.click_other.length; i++) {
                
    var item = window.click_other[i];
                
    if (item.target == this) {
                    window.click_other.splice(i, 
    1);
                    
    break;
                }
            }
        }
    }); 


  • 相关阅读:
    BZOJ 2818 Gcd 线性欧拉筛(Eratosthenes银幕)
    simlescalar CPU模拟器源代码分析
    基于webRTC技术 音频和视频,IM解
    SVM明确的解释1__ 线性可分问题
    Atititjs javascript异常处理机制java异常转换.js exception process
    hibernate annotation 相关主键生成策略
    切向量,普通矢量,渐变
    C++动态数组简单的模拟二元堆
    [Angular] Create a custom validator for reactive forms in Angular
    [RxJS] Marbles Testings
  • 原文地址:https://www.cnblogs.com/gateluck/p/1869092.html
Copyright © 2011-2022 走看看