我目前正在学习 Jquery,我是一个新手。目前我正在尝试使这个自定义滑块工作。我想要实现的是,当有人单击prev
或next
按钮时,滑块没有任何反应,但上面写的文本会发生变化,即转到下一个<li>
元素。我写了一些代码,它工作正常,但是当滑块在最后一个孩子上时问题就来了。当我单击下一个按钮时,文本消失了,现在我什至无法返回。我正在粘贴我在这里编写的所有代码,任何帮助将不胜感激,并将帮助我学习。多谢!
HTML
<ul class="testimonial-text">
<li class="test-current">
<p>“Sagittis risus nec venenatis. Ut laoreet iaculis massa et feugiat. Cras elementum quamvitae magna as elementum quamvitae magna porttitor in fermentum setlat ul.”</p>
<h4>Michel Buble & Tinta turner</h4>
</li>
<li>
<p>“Sagittis risus nec venenatis. Ut laoreet iaculis massa et feugiat. Cras elementum quamvitae magna as elementum quamvitae magna porttitor in fermentum setlat ul.”</p>
<h4>Rick Armstrong & Ashley Tist</h4>
</li>
<li>
<p>“Sagittis risus nec venenatis. Ut laoreet iaculis massa et feugiat. Cras elementum quamvitae magna as elementum quamvitae magna porttitor in fermentum setlat ul.”</p>
<h4>Mike Tran & Kimse Tricks</h4>
</li>
<li>
<p>“Sagittis risus nec venenatis. Ut laoreet iaculis massa et feugiat. Cras elementum quamvitae magna as elementum quamvitae magna porttitor in fermentum setlat ul.”</p>
<h4>Michel Buble & Tinta turner</h4>
</li>
<li>
<p>“Sagittis risus nec venenatis. Ut laoreet iaculis massa et feugiat. Cras elementum quamvitae magna as elementum quamvitae magna porttitor in fermentum setlat ul.”</p>
<h4>Michel Buble & Tinta turner</h4>
</li>
</ul>
按钮
<a class="testimonials-prev" ></a>
<a class="testimonials-next" ></a>
CSS
ul.testimonial-text{
list-style: none;
padding-top: 20px;
}
ul.testimonial-text li{
display: none;
}
ul.testimonial-text li.test-current{
display: block;
}
ul.testimonial-text li p{
text-align: center;
font-size: 18px;
color: #7c7c7c;
margin-bottom: 0px;
}
ul.testimonial-text li h4{
text-align: center;
text-transform: uppercase;
font-size: 16px;
}
ul.testimonial-images{
list-style: none;
}
ul.testimonial-images li{
display: inline-block;
margin-left: 16px;
opacity: 0.6;
}
ul.testimonial-images li:first-child{
display: inline-block;
margin-left: 0px;
}
a.testimonials-prev{
background: url('../images/icons/test-icons.png') no-repeat;
height: 80px;
width: 40px;
display: block;
margin-left: 10px;
cursor: pointer;
}
a.testimonials-next{
background: url('../images/icons/test-icons.png') no-repeat top right;
height: 80px;
width: 40px;
display: block;
cursor: pointer;
}
JQUERY / JAVASCRIPT
<script type="text/javascript">
$(document).ready(function() {
$("a.testimonials-next").click(function() {
$("ul.testimonial-text li.test-current").fadeOut('slow', function() {
$("ul.testimonial-text li.test-current").next().fadeIn('slow');
$("ul.testimonial-text li.test-current").next().addClass('test-current');
$("ul.testimonial-text li.test-current:first").removeClass('test-current');
});
});
$("a.testimonials-prev").click(function() {
$("ul.testimonial-text li.test-current").fadeOut('slow', function() {
$("ul.testimonial-text li.test-current").prev().fadeIn('slow');
$("ul.testimonial-text li.test-current").prev().addClass('test-current');
$("ul.testimonial-text li.test-current:last").removeClass('test-current');
});
});
});
</script>
如果代码马虎,我很抱歉。非常感谢!