febs-browser
Advanced tools
Comparing version 0.8.1 to 0.8.2
@@ -99,2 +99,8 @@ febs 库是一些常用的工具的合集; | ||
febs.dom.getDocumentPort():{width:number, height:number}; | ||
/** | ||
* @desc: 获取指定元素相对于视口的的offset | ||
* @return: | ||
*/ | ||
febs.dom.getElementOffset(e:any):{left:number, top:number}; | ||
``` | ||
@@ -101,0 +107,0 @@ |
@@ -27,2 +27,3 @@ ( function( global, factory ) { | ||
var utils = require('./utils'); | ||
var stringUtils = require('./string'); | ||
@@ -166,4 +167,7 @@ // - parentNodes 父节点 (HTMLNode) | ||
function _addClass( element,cName ){ | ||
if( !_hasClass( element,cName ) ){ | ||
element.className += " " + cName; | ||
if( !_hasClass( element,cName ) ){ | ||
if (stringUtils.isEmpty(element.className)) | ||
element.className += cName; | ||
else | ||
element.className += " " + cName; | ||
}; | ||
@@ -1448,4 +1452,52 @@ } | ||
/** | ||
* @desc: 获取指定元素相对于视口的的offset | ||
* @return: | ||
*/ | ||
Dom.getElementOffset = function(e) { | ||
if (!e) { | ||
return {}; | ||
} | ||
var ee = CreateDom(e); | ||
ee = ee[0]; | ||
if (ee) { | ||
if (typeof ee.getBoundingClientRect === 'function') { | ||
return { | ||
left: ee.left, | ||
top: ee.top | ||
}; | ||
} | ||
else { | ||
var actualLeft = ee.offsetLeft; | ||
var actualTop = ee.offsetTop; | ||
var current = ee.offsetParent; | ||
while (current !== null){ | ||
actualLeft += current.offsetLeft; | ||
actualTop += current.offsetTop; | ||
current = current.offsetParent; | ||
} | ||
var elementScrollLeft; | ||
var elementScrollTop; | ||
if (window.document.compatMode == "BackCompat"){ | ||
elementScrollLeft=window.document.body.scrollLeft; | ||
elementScrollTop=window.document.body.scrollTop; | ||
} else { | ||
elementScrollLeft=window.document.documentElement.scrollLeft; | ||
elementScrollTop=window.document.documentElement.scrollTop; | ||
} | ||
return { | ||
left: actualLeft-elementScrollLeft, | ||
top: actualTop-elementScrollTop | ||
}; | ||
} // if..else. | ||
} | ||
} | ||
return {Dom, CreateDom}; | ||
} | ||
); |
@@ -73,3 +73,3 @@ { | ||
"name": "febs-browser", | ||
"version": "0.8.1" | ||
"version": "0.8.2" | ||
} |
@@ -99,2 +99,8 @@ febs 库是一些常用的工具的合集; | ||
febs.dom.getDocumentPort():{width:number, height:number}; | ||
/** | ||
* @desc: 获取指定元素相对于视口的的offset | ||
* @return: | ||
*/ | ||
febs.dom.getElementOffset(e:any):{left:number, top:number}; | ||
``` | ||
@@ -101,0 +107,0 @@ |
@@ -496,2 +496,8 @@ // Type definitions for febs | ||
function getDocumentPort():{width:number, height:number};; | ||
/** | ||
* @desc: 获取指定元素相对于视口的的offset | ||
* @return: | ||
*/ | ||
function getElementOffset(e:any):{left:number, top:number}; | ||
} | ||
@@ -498,0 +504,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1492306
15459
488