过去几周我一直在努力解决这个问题,但我完全陷入困境!我希望有人可以提供建议,这样我就可以开始研究项目的其余部分了。
我正在尝试构建我的投资组合并将其分为四个部分。当我点击“投资组合”按钮'它目前同时打开所有.slidingDivs,最后一个显示在顶部。如何改进jQuery,使其仅针对用户点击的菜单项? (即当我点击' web'时,我希望它只打开' web' .slidingDiv)
我确定它非常明显,但感谢您提出的任何建议!
http://jsfiddle.net/pootletootle/u02au0vv/9/
$(document).ready(function () {
$(".slidingDiv").hide();
$(".show_hide").show();
$('.show_hide').click(function () {
$(".slidingDiv").slideToggle();
$(window).ready(function () {
$('.bxslider').bxSlider();
$(this).stop(true, false).bxSlider();
});
});
});
答案 0 :(得分:0)
尝试更新的代码(http://jsfiddle.net/u02au0vv/13/)
基于每个按钮都有一个类的事实。您需要做出的更改如下:
注意:确保唯一类是所有按钮中的第二个类,close和slidingDiv(否则更改函数中的类选择器索引)
$(document).ready(function() {
$(".slidingDiv").hide();
$(".show_hide").show();
$('.show_hide').click(function(event) {
var i = $(event.target).attr('class').split(' ')[1];
$('.slidingDiv.' + i).slideToggle();
$(window).ready(function() {
$('.bxslider').bxSlider();
$(this).stop(true, false).bxSlider();
});
});
});
@charset"utf-8";
/* CSS Document
#louise-scroller img {
max-width: 100%;
height: auto;
margin: 0;
}*/
html,
body,
.container,
.louise-scroller,
.louise-scroller section {
height: 100%;
margin: 0 !important;
}
/*__________________________________________________________________________________________________________
Navigation
*/
#louise-scroller nav {
width: 100%;
top: 5%;
z-index: 9999;
position: absolute;
text-align: center;
}
#louise-scroller nav a {
color: white;
font-size: 2em;
font-family: "Open Sans";
text-decoration: none;
margin: 0px 0.2em;
font-weight: 600;
}
#louise-scroller nav a:after {
content: '';
position: absolute;
}
#louise-scroller nav a:hover:after {
color: #888888;
}
#louise-scroller nav a.louise-current:after {
background: #888888;
}
.louise-current {
margin: 0 !important;
}
/* background-attachment does the trick */
#louise-scroller section {
position: relative;
background-position: top center;
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
}
/* Chrome, Safari, Opera */
@-webkit-keyframes mymove {
from {
left: -100%;
}
to {
left: 0;
}
}
@keyframes mymove {
from {
left: -100%;
}
to {
left: 0;
}
}
/* Chrome, Safari, Opera */
@-webkit-keyframes ohmove {
from {
right: -100%;
}
to {
right: 0;
}
}
@keyframes ohmove {
from {
right: -100%;
}
to {
right: 0;
}
}
#louise-scroller p {
font-size: 18px;
font-weight: 400;
letter-spacing: normal;
line-height: 28px;
margin: 0;
padding: 0 0 20px 0;
text-align: left;
}
/*__________________________________________________________________________________________________________
Portfolio
*/
#louise-scroller #portfolio {
background: #999999;
background-attachment: fixed;
/* custom background-position */
background-position: 50% 50%;
/* ie8- graceful degradation */
background-position: 50% 50%9 !important;
background-size: 100% 100%;
max-width: 100%;
}
#louise-scroller #portfolio h2 {
color: #ffffff;
margin: 0;
padding: 80px 0;
}
#louise-scroller #portfolio .ss-container {
width: 100%;
position: relative;
text-align: left;
float: left;
overflow: hidden;
/*padding-bottom: 500px;*/
padding: 0;
}
#louise-scroller #portfolio .ss-container a {
background: #222222;
background-size: 100%;
color: #ffffff;
display: block;
float: right;
font-family: Open Sans;
font-size: 28px;
font-weight: 400;
height: 114px !important;
letter-spacing: -1px;
line-height: 28px;
padding: 167px 0 0;
text-align: center;
text-decoration: none;
width: 500px !important;
}
#louise-scroller #portfolio .ss-container a.branding,
#louise-scroller #portfolio .ss-container a.graphics {
background: #444444;
}
#louise-scroller #portfolio .ss-container a.graphics,
#louise-scroller #portfolio .ss-container a.illustration {
float: left;
}
#louise-scroller #portfolio .ss-container a.illustration {
background: url('images/Large/Large_140925_Portfolio_Illustration2.jpg') no-repeat;
}
#louise-scroller #portfolio .ss-row {
width: 100%;
clear: both;
float: left;
position: relative;
padding: 0;
height: auto !important;
}
#louise-scroller #portfolio .ss-left,
#louise-scroller #portfolio .ss-right {
float: left;
width: 50%;
position: relative;
}
#louise-scroller #portfolio .ss-left {
text-align: right;
float: left;
}
/* Pop Up */
#louise-scroller #portfolio .reveal {
background: none repeat scroll 0 0 #FFFFFF;
display: block;
height: 100%;
position: absolute;
top: 0;
width: 100%;
}
.slidingDiv {
background: none repeat scroll 0 0 #FFFFFF;
display: block;
height: 100%;
position: absolute;
top: 0;
width: 100%;
}
.slidingDiv #close {
background: none repeat scroll 0 0 #EEEEEE;
color: #444444;
cursor: pointer;
display: block;
font-family: helvetica;
font-size: 25px;
height: 29px;
padding: 1px 0 0;
position: absolute;
right: 5%;
text-align: center;
text-decoration: none;
top: 2%;
width: 30px;
z-index: 99;
}
.show_hide {
display: none;
}
.bx-wrapper {
position: absolute !important;
}
.bx-wrapper img {
margin: 0 auto;
}
.bxslider img {
background: #FFCCFF;
display: block;
height: 300px;
margin: 0 auto;
width: 500px;
}
.bxslider img#two {
background: #CC99FF;
}
.bxslider img#two {
background: #99CCFF;
}
.bxslider img#two {
background: #CCFFFF;
}
.bxslider img#two {
background: #FFFF66;
}
.bxslider img#two {
background: #FF9933;
}
.bxslider img#two {
background: #FF6666;
}
.bxslider img#two {
background: #9966FF;
}
.bxslider img#two {
background: #6699FF;
}
.bxslider img#two {
background: #00FF00;
}
.bxslider img#two {
background: #996633;
}
.bxslider img#two {
background: #CC0000;
}
.bxslider img#two {
background: #993366;
}
.bxslider img#two {
background: #000052;
}
.bxslider img#two {
background: #0099CC;
}
.bxslider img#two {
background: #669999;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<section id="portfolio">
<h2>Portfolio</h2>
<!-- Portfolio Buttons-->
<div id="ss-container" class="ss-container">
<div class="ss-row">
<div class="ss-left">
<a href="javascript:;" class="show_hide web" id="0">Web</a>
</div>
<div class="ss-right">
<a href="javascript:;" class="show_hide graphics" id="1">Graphics</a>
</div>
</div>
<div class="ss-row ss-medium">
<div class="ss-left">
<a href="javascript:;" class="show_hide branding">Branding</a>
</div>
<div class="ss-right">
<a href="javascript:;" class="show_hide illustration">Illustration</a>
</div>
</div>
</div>
<!-- Pop Up & Flexslider -->
<div class="slidingDiv web">
<a href="javascript:;" class="show_hide web" id="close">X</a>
<ul class="bxslider web active">
<li>
<img src="http://www.bayesian-inference.com/images/ban-samplesize.png" />
</li>
<li>
<img src="images/Louise_Flanagan_2.jpg" />
</li>
<li>
<img src="images/Louise_Flanagan_3.jpg" />
</li>
<li>
<img src="images/Louise_Flanagan_4.jpg" />
</li>
</ul>
</div>
<div class="slidingDiv graphics">
<a href="javascript:;" class="show_hide graphics" id="close">X</a>
<ul class="bxslider graphics">
<li>
<img src="http://www.stardust.com/mm5/graphics/00000001/Established-Sons-Two-Timer-Clock-xl3.jpg" />
</li>
<li>
<img src="images/Louise_Flanagan_6.jpg" />
</li>
<li>
<img src="images/Louise_Flanagan_7.jpg" />
</li>
<li>
<img src="images/Louise_Flanagan_8.jpg" />
</li>
</ul>
</div>
<div class="slidingDiv branding">
<a href="javascript:;" class="show_hide branding" id="close">X</a>
<ul class="bxslider branding">
<li>
<img src="http://www.w3schools.com/images/w3logotest2.png" />
</li>
<li>
<img src="images/Louise_Flanagan_10.jpg" />
</li>
<li>
<img src="images/Louise_Flanagan_11.jpg" />
</li>
<li>
<img src="images/Louise_Flanagan_12.jpg" />
</li>
</ul>
</div>
<div class="slidingDiv illustration">
<a href="javascript:;" class="show_hide illustration" id="close">X</a>
<ul class="bxslider illustration">
<li>
<img src="images/Louise_Flanagan_13.jpg" />
</li>
<li>
<img src="images/Louise_Flanagan_14.jpg" />
</li>
<li>
<img src="images/Louise_Flanagan_15.jpg" />
</li>
<li>
<img src="images/Louise_Flanagan_16.jpg" />
</li>
</ul>
</div>
</section>
注意:我已经更改了前3个div中的第一个img src,以验证代码2是否正常工作。