JS.elementGetStyle(element, style)應(yīng)用示例
更新時(shí)間:2013年09月24日 08:48:43 作者:
獲取Dom元素的Style數(shù)組中的指定Style元素,下面有個(gè)不錯(cuò)的示例,感興趣的朋友可以參考下,希望對(duì)大家有所幫助
注: 獲取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)文章
JS使用正則表達(dá)式提交頁(yè)面驗(yàn)證的代碼
這篇文章主要介紹了JS使用正則表達(dá)式提交頁(yè)面驗(yàn)證的代碼,本文圖文實(shí)例代碼相結(jié)合給大家介紹的非常詳細(xì),需要的朋友可以參考下2019-10-10IE8 內(nèi)存泄露(內(nèi)存一直增長(zhǎng) )的原因及解決辦法
最近開發(fā)的時(shí)候?qū)?yè)面使用了定時(shí)的局部更新,結(jié)果在ie6,7和Firefox下,一切正常,而在ie8下過(guò)上幾個(gè)小時(shí)就瀏覽器就崩潰了,顯示是內(nèi)存溢出,下面由腳本之家小編給大家介紹ie8下內(nèi)存一直增長(zhǎng)內(nèi)存泄漏的原因及解決辦法,需要的朋友一起學(xué)習(xí)吧2016-04-04HTML5開發(fā)Kinect體感游戲的實(shí)例應(yīng)用
這篇文章主要介紹了HTML5開發(fā)Kinect體感游戲的實(shí)例應(yīng)用的相關(guān)資料,希望通過(guò)本文能夠幫助到大家,需要的朋友可以參考下2017-09-09使用swiper自定義分頁(yè)點(diǎn)擊跳轉(zhuǎn)指定頁(yè)面
這篇文章主要介紹了使用swiper自定義分頁(yè)點(diǎn)擊跳轉(zhuǎn)指定頁(yè)面方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-04-04javascript:window.open彈出窗口的位置問(wèn)題
這篇文章主要介紹了javascript:window.open彈出窗口的位置問(wèn)題,需要的朋友可以參考下2014-03-03JavaScript表單通過(guò)正則表達(dá)式驗(yàn)證電話號(hào)碼
通過(guò)正則表達(dá)式實(shí)現(xiàn)判斷一個(gè)輸入量是否為電話號(hào)碼,需要的朋友可以參考下2014-03-03