见如下代码:
// 获取当前页面最大z-index元素值
function getMaxZIndex() {
var maxZ = Math.max.apply(null, $.map($('body *'), function(e,n) {
if ($(e).css('position') != 'static') {
return parseInt($(e).css('z-index')) || -1;
}
}
));
return maxZ;
}
这里要说明下, 如果一个元素未设置z-index值, 那么将会取到auto.
如果不用jQuery, 也可考虑使用document.all || document.querySelectorAll("*")来获取所有元素,
使用window.getComputedStyle(ele, null).zIndex来获取元素的z-index值.
---------------------
作者:butterfly5211314
来源:CSDN
原文:https://blog.csdn.net/butterfly5211314/article/details/79488229
版权声明:本文为博主原创文章,转载请附上博文链接!