选择Z-index最高的DIV [英] Select DIV with highest z-index
问题描述
示例代码让我可以开始解释这个问题:
< div style =z-index:5> ; 5'; / DIV>
< div style =z-index:2> 2< / div>
< div style =z-index:1> 1< / div>
< div style =z-index:4> 4< / div>
< div style =z-index:3> 3< / div>
(z-index值无关紧要,它们的顺序更少,只是示例代码)
问题:我想选择具有最高z-index值的DIV(使用CSS或带jQuery的JS)。在上面的例子中,我想选择第一个,因为它的z-index 5比所有其他的z-索引高。
有没有办法做这个?
额外信息:我正在使用jQuery + jQuery UI编写简单窗口管理器,并且z-index由.draggable中的堆栈选项分配。
我似乎无法找到一种方法让jQuery为最后一个拖拽的元素分配一个类,所以我将采用最高的z-index方式。请帮忙吗?感谢。
我相信你可以使用stop事件来访问最近拖拽的项目, p>
$('。selector')。draggable({
stop:function(event,ui){
$(event.target).addClass('justDragged');
}
});
如果您希望查看绑定到事件的所有函数/变量,可以使用以下代码:
var str ='';
for(i in event){
str + = i +',';
}
alert(str);
这会给你一个很好的指示,你可以在任何数量的jQuery回调参数中使用它。 / p>
Example code so I can start explaining this problem:
<div style="z-index:5">5</div>
<div style="z-index:2">2</div>
<div style="z-index:1">1</div>
<div style="z-index:4">4</div>
<div style="z-index:3">3</div>
(z-index values do not matter, and their order, even less. Just example code)
Problem: I want to select (either using CSS or JS with jQuery) the DIV with highest z-index value. In the case above, I want to select the first one, because it's z-index 5 is higher than all the others' z-indexes.
Is there a way to do this? Extra information: I'm writing a Simple Window Manager with jQuery + jQuery UI, and the z-indexes are assigned by the stack option in .draggable. I can't seem to find a way to make jQuery to assign the last dragged element a class either, so I'm going by the highest z-index way. Any help please? Thanks.
I'm sure you could use the stop event to gain access to the recently dragged item, i.e.:
$('.selector').draggable({
stop: function(event, ui) {
$(event.target).addClass('justDragged');
}
});
If you wish to see all functions/variables bound to event, you could use the following:
var str = '';
for (i in event) {
str += i + ', ';
}
alert(str);
This should give you a good indication of what's available to you in any number of jQuery callback params.
这篇关于选择Z-index最高的DIV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!