event

作者: 那一抹流星 | 来源:发表于2017-11-29 17:02 被阅读0次

    1. 事件对象的获取

    var event = event || window.event; // 兼容写法, ie678中支持window.event

    2. event事件重要内容

    event.png

    3. screenX、pageX、clientX的区别:

    qubie.png

    3. 获取屏幕可视区域的宽高

     function client(){
            if(window.innerHeight !== undefined){
                return {
                    "width": window.innerWidth,
                    "height": window.innerHeight
                }
            }else if(document.compatMode === "CSS1Compat"){
                return {
                    "width": document.documentElement.clientWidth,
                    "height": document.documentElement.clientHeight
                }
            }else{
                return {
                    "width": document.body.clientWidth,
                    "height": document.body.clientHeight
                }
            }
        }
    
    // 阻止冒泡
      event = event || window.event;
    
      if(event && event.stopPropagation){
             event.stopPropagation();
       }else{
            event.cancelBubble = true; // IE10以下
       }
    
    // 获取目标元素的兼容写法:
    var obj = event.target ? event.target : event.srcElement;
    

    相关文章

      网友评论

          本文标题:event

          本文链接:https://www.haomeiwen.com/subject/ivkubxtx.html