3 回答

TA貢獻1860條經驗 獲得超8個贊
您可以findHighestZIndex像這樣調用特定的元素類型,例如“ DIV”:
findHighestZIndex('div');
假設findHighestZindex函數定義如下:
function findHighestZIndex(elem)
{
var elems = document.getElementsByTagName(elem);
var highest = 0;
for (var i = 0; i < elems.length; i++)
{
var zindex=document.defaultView.getComputedStyle(elems[i],null).getPropertyValue("z-index");
if ((zindex > highest) && (zindex != 'auto'))
{
highest = zindex;
}
}
return highest;
}

TA貢獻1828條經驗 獲得超6個贊
為了清楚起見,從abcoder站點竊取了一些代碼:
var maxZ = Math.max.apply(null,
$.map($('body *'), function(e,n) {
if ($(e).css('position') != 'static')
return parseInt($(e).css('z-index')) || 1;
}));

TA貢獻1828條經驗 獲得超3個贊
使用ES6更清潔的方法
function maxZIndex() {
return Array.from(document.querySelectorAll('body *'))
.map(a => parseFloat(window.getComputedStyle(a).zIndex))
.filter(a => !isNaN(a))
.sort()
.pop();
}
- 3 回答
- 0 關注
- 486 瀏覽
相關問題推薦
添加回答
舉報