[英]How to i get the click function to stop working when the last child is shown?
This is the html, the pages-nr have a fixed width with an overflow:hidden : 这是html,pages-nr具有固定的宽度,带有溢出:hidden:
<div class="pages-scroll">
<div class="pages-rightarrow"></div>
<div class="articles-pages">
<div class="pages-nr">
<a href="javascript:void(0)">1</a>
<a href="javascript:void(0)">2</a>
<a href="javascript:void(0)">3</a>
<a href="javascript:void(0)">4</a>
<a href="javascript:void(0)">5</a>
<a href="javascript:void(0)">6</a>
<a href="javascript:void(0)">7</a>
<a href="javascript:void(0)">8</a>
</div>
</div>
<div class="pages-leftarrow"></div>
</div>
This is the script i wrote so far and i donno what to ask 'if' to do so the arrows will be hidden when i reach the last div or the first div. 这是我到目前为止编写的脚本,我不问“如果”要做什么,因此当我到达最后一个div或第一个div时,箭头将被隐藏。
$('.pages-leftarrow').click(function () {
if ( $('.pages-nr a').hasClass('????') ) {
$('.pages-rightarrow').hide();
}
else {
$('.pages-nr').css({"margin-left": function(index, value) {
return parseFloat(value) - 44}
});
}
});
Here is the jsFiddle: http://jsfiddle.net/Na3W7/4/ This is the meat of the code that's run on startup: 这是jsFiddle: http : //jsfiddle.net/Na3W7/4/这是启动时运行的代码的主要内容:
$('.pages-nr a:not(:first),.pages-leftarrow').hide();
$('.pages-rightarrow').click(function(e){
e.preventDefault();
var $nextPage = $('.pages-nr a:visible:first').hide().next().show();
if($nextPage.is('.pages-nr a:last-child')){
$(e.target).hide();
}
if($('.pages-nr a:first').is(':visible')) {
$('.pages-leftarrow').hide();
}
else {
$('.pages-leftarrow').show();
}
});
$('.pages-leftarrow').click(function(e){
e.preventDefault();
var $prevPage = $('.pages-nr a:visible:first').hide().prev().show();
if($prevPage.is('.pages-nr a:first-child')){
$(e.target).hide();
}
if($('.pages-nr a:last').is(':visible')) {
$('.pages-rightarrow').hide();
}
else {
$('.pages-rightarrow').show();
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.