js 获取高度,宽度,绑定事件

获取滚动条高度:

document.documentElement.scrollTop

 

 

 

绑定事件:

var addEvent = (function () {
            if (document.addEventListener) {
                return function (el, type, fn) {
                    if (el.length) {
                        for (var i = 0; i < el.length; i++) {
                            addEvent(el[i], type, fn);
                        }
                    } else {
                        el.addEventListener(type, fn, false);
                    }
                };
            } else {
                return function (el, type, fn) {
                    if (el.length) {
                        for (var i = 0; i < el.length; i++) {
                            addEvent(el[i], type, fn);
                        }
                    } else {
                        el.attachEvent('on' + type, function () {
                            return fn.call(el, window.event);
                        });
                    }
                };
            }
        })();


        addEvent(window, 'scroll', fixedFun);

posted on 2012-08-21 17:11  lzf0514  阅读(171)  评论(0编辑  收藏  举报

导航