1.获取滚动条高度

  1 var top=document.body.scrollTop||document.documentElement.scrollTop;

 

2.事件监听

  1 var addEvent = function (obj, ev ,fn)
  2 {
  3     if(obj.attachEvent){
  4         obj.attachEvent('on'+ev, fn);
  5     }else{
  6         obj.addEventListener(ev, fn, false);
  7     }
  8 };

 

 

3.事件移除

  1 var removeEvent = function(element, type, handler){
  2         if (element.removeEventListener) {
  3             element.removeEventListener(type, handler, false);
  4         }
  5         else if (element.detachEvent) {
  6                 element.detachEvent("on" + type, handler);
  7         }
  8         else {
  9                 element["on" + type] = null;
 10         }
 11 }

 

4.阻止默认事件

  1 function(event){
  2         if (event.preventDefault) {
  3             event.preventDefault();
  4         }
  5         else {
  6             event.returnValue = false;
  7         }
  8 }

 

5.阻止事件冒泡

  1 function(event){
  2         if (event.stopPropagation) {
  3             event.stopPropagation();
  4         }
  5         else {
  6             event.cancelBubble = true;
  7         }
  8 }

 

6.元素的子节点

  1 var getChildNode=function(obj)
  2 {
  3     var childArr = [];
  4     var l=obj.childNodes.length;
  5     for (var i=0;i<l;i++)
  6         {
  7             if(obj.childNodes[i].nodeType==1)
  8                 {
  9                     childArr.push(obj.childNodes[i]);
 10                 }
 11         }
 12     return childArr;
 13 }
posted on 2016-05-10 15:58  百里登风  阅读(373)  评论(0编辑  收藏  举报