[英]z-index image not showing when used next prev button like image gallery using jquery
$(document).ready(function(){ $(".divs div.panel").each(function(e) { if (e > 2) $(this).hide(); console.log(e); }); $("#next").click(function(){ if ($(".divs div.panel:visible:last").next().length != 0){ $(".divs div.panel:visible:last").next().show(); $(".divs div.panel:visible:last").next().show(); $(".divs div.panel:visible:first").hide(); $(".divs div.panel:visible:first").hide(); } else { //either hide the next button or show 1st two again. :) } return false; }); $("#prev").click(function(){ if ($(".divs div.panel:visible:first").prev().length != 0){ var curVisLen = $(".divs div.panel:visible").length; $(".divs div.panel:visible:first").prev().show(); $(".divs div.panel:visible:first").prev().show(); $(".divs div.panel:visible:last").hide(); if(curVisLen == 3){ $(".divs div.panel:visible:last").hide(); } } else { // either hide the button or show last two divs // $(".divs div.panel:visible").hide(); // $(".divs div.panel:last").show(); } return false; }); });
body{ background-color: grey; } .dash-img-dv{ position: absolute; width: 170px; height: 221px; -moz-box-shadow: inset 5px -59px 63px 4px #5642BE; -webkit-box-shadow: inset 5px -59px 63px 4px #5642BE; box-shadow: inset 5px -59px 63px 4px #5642BE; } .dash-img-dv img { width: 170px; height: 221px; position: relative; z-index: -1; } .dash-img-dv-ttle{ position: relative; width: 153px; height: 50px; color: #fff; margin-left: 16px; margin-top: 167px; z-index: 1; } .panel{ display: inline-block; margin-left: 10px; } .gallery { background: #CCC; position: relative; margin: 0 auto; padding-top: 22px; } .prev-next-button { position: absolute; top: 50%; width: 30px; height: 30px; border-radius: 50%; background: #5642BE; transform: translateY(-50%); } .prev-next-button a{ color: #fff; position: absolute; left: 28%; top: 21%; } .previous { left: -16px; } .next { right: -16px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="gallery"> <div class="divs"> <div class="panel"> <div class="dash-img-dv"> <img src="http://www.istockphoto.com/resources/images/PhotoFTLP/img_63351521.jpg"> </div> <div class="dash-img-dv-ttle"> <p>This is title1</p> </div> </div> <div class="panel"> <div class="dash-img-dv"> <img src="http://www.istockphoto.com/resources/images/PhotoFTLP/img_63351521.jpg"> </div> <div class="dash-img-dv-ttle"> <p>This is title2</p> </div> </div> <div class="panel"> <div class="dash-img-dv"> <img src="http://www.istockphoto.com/resources/images/PhotoFTLP/img_63351521.jpg"> </div> <div class="dash-img-dv-ttle"> <p>This is title3</p> </div> </div> <div class="panel"> <div class="dash-img-dv"> <img src="http://www.istockphoto.com/resources/images/PhotoFTLP/img_63351521.jpg"> </div> <div class="dash-img-dv-ttle"> <p>This is title4</p> </div> </div> <div class="panel"> <div class="dash-img-dv"> <img src="http://www.istockphoto.com/resources/images/PhotoFTLP/img_63351521.jpg"> </div> <div class="dash-img-dv-ttle"> <p>This is title5</p> </div> </div> <div class="panel"> <div class="dash-img-dv"> <img src="http://www.istockphoto.com/resources/images/PhotoFTLP/img_63351521.jpg"> </div> <div class="dash-img-dv-ttle"> <p>This is title6</p> </div> </div> <div class="panel"> <div class="dash-img-dv"> <img src="http://www.istockphoto.com/resources/images/PhotoFTLP/img_63351521.jpg"> </div> <div class="dash-img-dv-ttle"> <p>This is title7</p> </div> </div> </div> <!-- <a id="prev">prev</a> <a id="next">next</a> --> <div class="prev-next-button previous"> <a id="prev"><span class="fa fa-chevron-left"></span></a> </div> <div class="prev-next-button next"> <a id="next"><span class="fa fa-chevron-right"></span></a> </div> </div>
I want to show my next previous div with images using jquery. 我想用jQuery显示我的下一个div与图像。 I tried something like bellow.Everything is almost fine but problem is now that the images is not showing. 我尝试了类似波纹管的东西,一切都很好,但是现在的问题是图像没有显示。 Is there any z-index problem or something like that? 是否有z-index问题或类似问题? I could not find the reason why images are not showing. 我找不到图像无法显示的原因。 Would anyone please help me to show the images?Here is the image bellow before write the script 有人能帮我显示图片吗?这是写脚本之前的下面的图片
The negative z-index
on the image will push it behind everything else on the page that isn't positioned. 图像上的负z-index
会将其推到页面上其他所有未定位的位置之后。 Add a z-index
to .panel
so that the negative z-index
on the image doesn't push it behind .panel
and keeps it between .panel
and the element with the inner box shadow you want it to appear below. 向.panel
添加一个z-index
以使图像上的负z-index
不会将其推到.panel
后面,并且将其保持在.panel
和您希望其在下面显示的带有内部阴影的元素之间。
$(document).ready(function(){ $(".divs div.panel").each(function(e) { if (e > 2) $(this).hide(); console.log(e); }); $("#next").click(function(){ if ($(".divs div.panel:visible:last").next().length != 0){ $(".divs div.panel:visible:last").next().show(); $(".divs div.panel:visible:last").next().show(); $(".divs div.panel:visible:first").hide(); $(".divs div.panel:visible:first").hide(); } else { //either hide the next button or show 1st two again. :) } return false; }); $("#prev").click(function(){ if ($(".divs div.panel:visible:first").prev().length != 0){ var curVisLen = $(".divs div.panel:visible").length; $(".divs div.panel:visible:first").prev().show(); $(".divs div.panel:visible:first").prev().show(); $(".divs div.panel:visible:last").hide(); if(curVisLen == 3){ $(".divs div.panel:visible:last").hide(); } } else { // either hide the button or show last two divs // $(".divs div.panel:visible").hide(); // $(".divs div.panel:last").show(); } return false; }); });
body{ background-color: grey; } .dash-img-dv{ position: absolute; width: 170px; height: 221px; -moz-box-shadow: inset 5px -59px 63px 4px #5642BE; -webkit-box-shadow: inset 5px -59px 63px 4px #5642BE; box-shadow: inset 5px -59px 63px 4px #5642BE; } .dash-img-dv img { width: 170px; height: 221px; position: relative; z-index: -1; } .dash-img-dv-ttle{ position: relative; width: 153px; height: 50px; color: #fff; margin-left: 16px; margin-top: 167px; z-index: 1; } .panel{ display: inline-block; margin-left: 10px; position: relative; z-index: 1; } .gallery { background: #CCC; position: relative; margin: 0 auto; padding-top: 22px; } .prev-next-button { position: absolute; top: 50%; width: 30px; height: 30px; border-radius: 50%; background: #5642BE; transform: translateY(-50%); } .prev-next-button a{ color: #fff; position: absolute; left: 28%; top: 21%; } .previous { left: -16px; } .next { right: -16px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="gallery"> <div class="divs"> <div class="panel"> <div class="dash-img-dv"> <img src="http://www.istockphoto.com/resources/images/PhotoFTLP/img_63351521.jpg"> </div> <div class="dash-img-dv-ttle"> <p>This is title1</p> </div> </div> <div class="panel"> <div class="dash-img-dv"> <img src="http://www.istockphoto.com/resources/images/PhotoFTLP/img_63351521.jpg"> </div> <div class="dash-img-dv-ttle"> <p>This is title2</p> </div> </div> <div class="panel"> <div class="dash-img-dv"> <img src="http://www.istockphoto.com/resources/images/PhotoFTLP/img_63351521.jpg"> </div> <div class="dash-img-dv-ttle"> <p>This is title3</p> </div> </div> <div class="panel"> <div class="dash-img-dv"> <img src="http://www.istockphoto.com/resources/images/PhotoFTLP/img_63351521.jpg"> </div> <div class="dash-img-dv-ttle"> <p>This is title4</p> </div> </div> <div class="panel"> <div class="dash-img-dv"> <img src="http://www.istockphoto.com/resources/images/PhotoFTLP/img_63351521.jpg"> </div> <div class="dash-img-dv-ttle"> <p>This is title5</p> </div> </div> <div class="panel"> <div class="dash-img-dv"> <img src="http://www.istockphoto.com/resources/images/PhotoFTLP/img_63351521.jpg"> </div> <div class="dash-img-dv-ttle"> <p>This is title6</p> </div> </div> <div class="panel"> <div class="dash-img-dv"> <img src="http://www.istockphoto.com/resources/images/PhotoFTLP/img_63351521.jpg"> </div> <div class="dash-img-dv-ttle"> <p>This is title7</p> </div> </div> </div> <!-- <a id="prev">prev</a> <a id="next">next</a> --> <div class="prev-next-button previous"> <a id="prev"><span class="fa fa-chevron-left"></span></a> </div> <div class="prev-next-button next"> <a id="next"><span class="fa fa-chevron-right"></span></a> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.