首頁 > web前端 > js教程 > 主體

JS.elementGetStyle(element, style)應用範例_javascript技巧

WBOY
發布: 2016-05-16 17:21:40
原創
1486 人瀏覽過

注: 獲取Dom元素的Style數組中的指定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; ;
} else if (element.currentStyle) {
value = element.currentStyle[style];
}
}


/**需要DGF嗎?
if (window.opera && ['左', '上', '右', '下'].include(style))
if (Element.getStyle(element, '位置') == '靜態')值='自動';*/


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.originalColor == undefined) { // avoid picking up highlight> .originalColor = elementGetStyle(element, "background-color");
}
elementSetStyle(element, {"backgroundColor" : highLightColor});
window.setTimeout(functiontry> {
window.setTimeout(functiontry> {
window.setTimeout(function (try)>
//if element is orphan, probably page of it has already gone, so ignore
if (!element.parentNode) {
return;
}
elementSetStyle( ": element.originalColor });
} catch (e) { } // DGF unhighlighting is very dangerous and low priority
}, 200);
}
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!