gpt4 book ai didi

jquery - 通过单击另一个更改元素 z-index

转载 作者:太空宇宙 更新时间:2023-11-03 18:28:41 24 4
gpt4 key购买 nike

提前感谢您的任何帮助或建议,如果我的英语不好,我深表歉意:)

我有一个这样的 html 元素:

<a id="menu-click" onclick="$('#menu-left').slideToggle('fast');return false;"></a>

点击这个元素打开一个菜单什么的往下滑,就可以了。但是因为我在页面上有更多可拖动的框,所以这个菜单可以在它们下面滑动。我的意图是,在单击菜单后单击检查页面上的高 z-index 添加 +1 到此 z-index 并将其分配给菜单左侧。我需要此功能适用于更多相似的元素。

我已经为可拖动框使用了 jQuery 函数,它工作得很好。但我不知道如何为点击另一个元素后打开的元素创建一个函数。

这是我用于框的函数:

$(function() {
var c = [
"#box1",
"#box2",
"#box3",
"#box4"
];
var boxes = c.join(", ");
// Set up mousedown handlers for each box
$(boxes).mousedown(function() {
var el = $(this), // The box that was clicked
max = 0;

// Find the highest z-index
$(boxes).each(function() {
// Find the current z-index value
var z = parseInt( $( this ).css( "z-index" ), 10 );
// Keep either the current max, or the current z-index, whichever is higher
max = Math.max( max, z );
});

// Set the box that was clicked to the highest z-index plus one
el.css("z-index", max + 1 );
});
});

最佳答案

技巧就在这里。

$(function() {
var c = [
"#box1",
"#box2",
"#box3",
"#box4"
];
var boxes = c.join(", ");
// Set up mousedown handlers for each box
$(boxes).mousedown(function() {
var el = $(this), // The box that was clicked
max = 0;

// Find the highest z-index
$(boxes).each(function() {
$( this ).css( "z-index" , 10); //first assign the value and then get it
// Find the current z-index value
var z = parseInt( $( this ).css( "z-index" ));//get the zindex after assigning
// Keep either the current max, or the current z-index, whichever is higher
max = Math.max( max, z );
});

// Set the box that was clicked to the highest z-index plus one
el.css("z-index", max + 1 );
});

});

关于jquery - 通过单击另一个更改元素 z-index,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20283306/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com