我正在尝试实现以下内容:
- 点击链接触发一个函数,该函数将.show一个DIV(#page-cover),使整个背景变暗。 这个div的z-index为999
- 然后我想要另一个div(#red)出现在暗淡的背景上/淡入/显示,并具有更高的z-index
我的CSS:
我的CSS:
#page-cover {
display: none;
position: fixed;
width: 100%;
height: 100%;
background-color: #000;
z-index: 999;
top: 0;
left: 0;
}
#red {
background-color: red;
width: 100px;
height: 100px;
}
HTML
//Triggering link
<a href="#" onclick="dimBackground("Element1")">Element 1</a>
//Div to appear upon dimmed DIV
<div id="red">hejsa</div>
//Dimming DIV
<div id="page-cover"></div>
jQuery
function dimBackground() {
$("#page-cover").css("opacity",0.6).fadeIn(300, function () {
//Attempting to set/make #red appear upon the dimmed DIV
$('#red').css('zIndex', 10000);
});
}
页面封面按照预期渐变,但我无法使#red在其后出现。
有什么建议吗?