无法使用JQuery更改z-index [英] Can't change z-index with JQuery
问题描述
由于某种原因,我无法使用jQuery更改元素的zIndex。我搜索了所有这个网站和谷歌,但找不到正确的答案。
我试图在点击按钮时将我的元素放在另一个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屋!