JS.elementGetStyle(element, style)應(yīng)用示例
更新時間:2013年09月24日 08:48:43 作者:
獲取Dom元素的Style數(shù)組中的指定Style元素,下面有個不錯的示例,感興趣的朋友可以參考下,希望對大家有所幫助
注: 獲取Dom元素的Style數(shù)組中的指定Style元素
function elementGetStyle(element, style) {
var value = null;
if (element.style) {
value = element.style[style];
}
if (!value) {
if (document.defaultView && document.defaultView.getComputedStyle) {
var css = document.defaultView.getComputedStyle(element, null);
value = css ? css.getPropertyValue(style) : null;
} else if (element.currentStyle) {
value = element.currentStyle[style];
}
}
/** DGF necessary?
if (window.opera && ['left', 'top', 'right', 'bottom'].include(style))
if (Element.getStyle(element, 'position') == 'static') value = 'auto'; */
return value == 'auto' ? null : value;
}
注:選定的Dom元素以color顏色高亮0.2s
function UiWebhighlight(element,color) {
if (!element) {return}
var highLightColor = "yellow";
if (color) {highLightColor = color}
if (element.originalColor == undefined) { // avoid picking up highlight
element.originalColor = elementGetStyle(element, "background-color");
}
elementSetStyle(element, {"backgroundColor" : highLightColor});
window.setTimeout(function () {
try {
//if element is orphan, probably page of it has already gone, so ignore
if (!element.parentNode) {
return;
}
elementSetStyle(element, { "backgroundColor": element.originalColor });
} catch (e) { } // DGF unhighlighting is very dangerous and low priority
}, 200);
}
復(fù)制代碼 代碼如下:
function elementGetStyle(element, style) {
var value = null;
if (element.style) {
value = element.style[style];
}
if (!value) {
if (document.defaultView && document.defaultView.getComputedStyle) {
var css = document.defaultView.getComputedStyle(element, null);
value = css ? css.getPropertyValue(style) : null;
} else if (element.currentStyle) {
value = element.currentStyle[style];
}
}
/** DGF necessary?
if (window.opera && ['left', 'top', 'right', 'bottom'].include(style))
if (Element.getStyle(element, 'position') == 'static') value = 'auto'; */
return value == 'auto' ? null : value;
}
注:選定的Dom元素以color顏色高亮0.2s
復(fù)制代碼 代碼如下:
function UiWebhighlight(element,color) {
if (!element) {return}
var highLightColor = "yellow";
if (color) {highLightColor = color}
if (element.originalColor == undefined) { // avoid picking up highlight
element.originalColor = elementGetStyle(element, "background-color");
}
elementSetStyle(element, {"backgroundColor" : highLightColor});
window.setTimeout(function () {
try {
//if element is orphan, probably page of it has already gone, so ignore
if (!element.parentNode) {
return;
}
elementSetStyle(element, { "backgroundColor": element.originalColor });
} catch (e) { } // DGF unhighlighting is very dangerous and low priority
}, 200);
}
相關(guān)文章
IE8 內(nèi)存泄露(內(nèi)存一直增長 )的原因及解決辦法
最近開發(fā)的時候?qū)撁媸褂昧硕〞r的局部更新,結(jié)果在ie6,7和Firefox下,一切正常,而在ie8下過上幾個小時就瀏覽器就崩潰了,顯示是內(nèi)存溢出,下面由腳本之家小編給大家介紹ie8下內(nèi)存一直增長內(nèi)存泄漏的原因及解決辦法,需要的朋友一起學(xué)習(xí)吧2016-04-04HTML5開發(fā)Kinect體感游戲的實例應(yīng)用
這篇文章主要介紹了HTML5開發(fā)Kinect體感游戲的實例應(yīng)用的相關(guān)資料,希望通過本文能夠幫助到大家,需要的朋友可以參考下2017-09-09javascript:window.open彈出窗口的位置問題
這篇文章主要介紹了javascript:window.open彈出窗口的位置問題,需要的朋友可以參考下2014-03-03