lau*_*kok 6 jquery z-index jquery-1.9
如何在文档中找到最高的z-index,无论它们是什么标签?
我找到了这个代码,但我测试了它,它不起作用,
//include jQuery.js -- visit: http://jquery.com/
$(function(){
var maxZ = Math.max.apply(null,$.map($('body > *'), function(e,n){
if($(e).css('position')=='absolute')
return parseInt($(e).css('z-index'))||1 ;
})
);
alert(maxZ);
});
Run Code Online (Sandbox Code Playgroud)
有没有更好的办法呢?
编辑:
如果我将代码更改为此似乎有效,
$('body *')
$('body > *') --> is for div only I guess.
Run Code Online (Sandbox Code Playgroud)
这不是最有效的解决方案,但应该可行.jsFiddle.
请注意,您必须指定一个位置,以便z-index返回一个值.
var highest = -999;
$("*").each(function() {
var current = parseInt($(this).css("z-index"), 10);
if(current && highest < current) highest = current;
});
alert(highest);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5865 次 |
| 最近记录: |