我有一个由许多嵌套、绝对定位元素组成的复杂结构。
这些元素可能有也可能没有设置 z-index。
它们也可能具有也可能不具有相同的父元素。
我想知道返回哪个元素位于“顶部”的最佳/最简单方法是什么。类似于以下内容...
$(".panel").topMost()
(提前)感谢您的帮助
最佳答案
您的意思是 z-index 最高的元素:
$(document).ready(function() {
var array = [];
$("*").each(function() {
array.push($(this).css("z-index"));
});
var highest = Math.max.apply(Math, array);
console.log(highest);
});
关于javascript - 如何确定顶部元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14950026/