iutil.js
上传用户:shjgzm
上传日期:2017-08-31
资源大小:2757k
文件大小:5k
- /**
- * Interface Elements for jQuery
- * utility function
- *
- * http://interface.eyecon.ro
- *
- * Copyright (c) 2006 Stefan Petre
- * Dual licensed under the MIT (MIT-LICENSE.txt)
- * and GPL (GPL-LICENSE.txt) licenses.
- *
- *
- */
- jQuery.iUtil = {
- getPos : function (e, s)
- {
- var l = 0;
- var t = 0;
- var sl = 0;
- var st = 0;
- var w = jQuery.css(e,'width');
- var h = jQuery.css(e,'height');
- var wb = e.offsetWidth;
- var hb = e.offsetHeight;
- while (e.offsetParent){
- l += e.offsetLeft + (e.currentStyle?parseInt(e.currentStyle.borderLeftWidth)||0:0);
- t += e.offsetTop + (e.currentStyle?parseInt(e.currentStyle.borderTopWidth)||0:0);
- if (s) {
- sl += e.parentNode.scrollLeft||0;
- st += e.parentNode.scrollTop||0;
- }
- e = e.offsetParent;
- }
- l += e.offsetLeft + (e.currentStyle?parseInt(e.currentStyle.borderLeftWidth)||0:0);
- t += e.offsetTop + (e.currentStyle?parseInt(e.currentStyle.borderTopWidth)||0:0);
- st = t - st;
- sl = l - sl;
- return {x:l, y:t, sx:sl, sy:st, w:w, h:h, wb:wb, hb:hb};
- },
- getPosition : function(e)
- {
- var x = 0;
- var y = 0;
- var restoreStyle = false;
- es = e.style;
- if (jQuery(e).css('display') == 'none') {
- oldVisibility = es.visibility;
- oldPosition = es.position;
- es.visibility = 'hidden';
- es.display = 'block';
- es.position = 'absolute';
- restoreStyle = true;
- }
- el = e;
- while (el){
- x += el.offsetLeft + (el.currentStyle && !jQuery.browser.opera ?parseInt(el.currentStyle.borderLeftWidth)||0:0);
- y += el.offsetTop + (el.currentStyle && !jQuery.browser.opera ?parseInt(el.currentStyle.borderTopWidth)||0:0);
- el = el.offsetParent;
- }
- el = e;
- while (el && el.tagName.toLowerCase() != 'body')
- {
- x -= el.scrollLeft||0;
- y -= el.scrollTop||0;
- el = el.parentNode;
- }
- if (restoreStyle) {
- es.display = 'none';
- es.position = oldPosition;
- es.visibility = oldVisibility;
- }
- return {x:x, y:y};
- },
- getSize : function(e)
- {
- var w = jQuery.css(e,'width');
- var h = jQuery.css(e,'height');
- var wb = 0;
- var hb = 0;
- es = e.style;
- if (jQuery(e).css('display') != 'none') {
- wb = e.offsetWidth;
- hb = e.offsetHeight;
- } else {
- oldVisibility = es.visibility;
- oldPosition = es.position;
- es.visibility = 'hidden';
- es.display = 'block';
- es.position = 'absolute';
- wb = e.offsetWidth;
- hb = e.offsetHeight;
- es.display = 'none';
- es.position = oldPosition;
- es.visibility = oldVisibility;
- }
- return {w:w, h:h, wb:wb, hb:hb};
- },
- getClient : function(e)
- {
- if (e) {
- w = e.clientWidth;
- h = e.clientHeight;
- } else {
- de = document.documentElement;
- w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
- h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
- }
- return {w:w,h:h};
- },
- getScroll : function (e)
- {
- if (e) {
- t = e.scrollTop;
- l = e.scrollLeft;
- w = e.scrollWidth;
- h = e.scrollHeight;
- iw = 0;
- ih = 0;
- } else {
- if (document.documentElement && document.documentElement.scrollTop) {
- t = document.documentElement.scrollTop;
- l = document.documentElement.scrollLeft;
- w = document.documentElement.scrollWidth;
- h = document.documentElement.scrollHeight;
- } else if (document.body) {
- t = document.body.scrollTop;
- l = document.body.scrollLeft;
- w = document.body.scrollWidth;
- h = document.body.scrollHeight;
- }
- iw = self.innerWidth||document.documentElement.clientWidth||document.body.clientWidth||0;
- ih = self.innerHeight||document.documentElement.clientHeight||document.body.clientHeight||0;
- }
- return { t: t, l: l, w: w, h: h, iw: iw, ih: ih };
- },
- getMargins : function(e, toInteger)
- {
- el = jQuery(e);
- t = el.css('marginTop') || '';
- r = el.css('marginRight') || '';
- b = el.css('marginBottom') || '';
- l = el.css('marginLeft') || '';
- if (toInteger)
- return {
- t: parseInt(t)||0,
- r: parseInt(r)||0,
- b: parseInt(b)||0,
- l: parseInt(l)
- };
- else
- return {t: t, r: r, b: b, l: l};
- },
- getPadding : function(e, toInteger)
- {
- el = jQuery(e);
- t = el.css('paddingTop') || '';
- r = el.css('paddingRight') || '';
- b = el.css('paddingBottom') || '';
- l = el.css('paddingLeft') || '';
- if (toInteger)
- return {
- t: parseInt(t)||0,
- r: parseInt(r)||0,
- b: parseInt(b)||0,
- l: parseInt(l)
- };
- else
- return {t: t, r: r, b: b, l: l};
- },
- getBorder : function(e, toInteger)
- {
- el = jQuery(e);
- t = el.css('borderTopWidth') || '';
- r = el.css('borderRightWidth') || '';
- b = el.css('borderBottomWidth') || '';
- l = el.css('borderLeftWidth') || '';
- if (toInteger)
- return {
- t: parseInt(t)||0,
- r: parseInt(r)||0,
- b: parseInt(b)||0,
- l: parseInt(l)||0
- };
- else
- return {t: t, r: r, b: b, l: l};
- },
- getPointer : function(event)
- {
- x = event.pageX || (event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft)) || 0;
- y = event.pageY || (event.clientY + (document.documentElement.scrollTop || document.body.scrollTop)) || 0;
- return {x:x, y:y};
- }
- };