无法使用JQuery更改z-index [英] Can't change z-index with JQuery
问题描述
由于某种原因,我无法使用jQuery更改元素的zIndex.我已经搜索了所有该网站和Google,但找不到正确的答案.单击按钮时,我试图将我的元素放在另一个div的前面.我使用了您可以在此处看到的代码.但是没用.
I, for some reason, can't change the zIndex of an element using jQuery. I've searched all of this website and Google but couldn't find the right answer. I am trying to put my element in front of another div when clicking a button. I used the code you can see under here. But didn't work.
$(this).parent().css('zIndex',3000);
开头的元素的CSS代码:
CSS code of elements it's under in the begin:
#wall{
width:100%;
height:700px;
position: absolute;
top:500px;
background: #11c1e7;
opacity: 0.6;
z-index: 900;
}
该元素之上的CSS代码:
CSS code of element that should go above this:
.port1 {
width:200px;
height:200px;
left:<?php echo rand(1,1000); ?>px;
top:-500px;
border-radius: 500px;
background:red;
position:absolute;
z-index: 10;
}
有人知道我该如何解决吗?
Does anyone know how I can fix this?
//编辑
链接到该站点: http://dannypostma.com/project/j.php
单击组合球时,两个球会从空中掉落.单击时,它们应放在水的前面.
When clicking the portfolio ball, two balls drop from the air. These should go in front of the water when clicked.
推荐答案
设置 style.zIndex
属性对未定位的元素无效,即元素必须绝对定位,相对定位或固定.
Setting the style.zIndex
property has no effect on non-positioned elements, that is, the element must be either absolutely positioned, relatively positioned, or fixed.
所以我会尝试:
$(this).parent().css('position', 'relative');
$(this).parent().css('z-index', 3000);
这篇关于无法使用JQuery更改z-index的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!