- 首先,有一行图片的下方有一个“See more”按钮 。
- 当单击“See more”按钮时,在第一行图像之后添加第二行图像,并且“See more”按钮被替换为“See less”按钮。
- 当单击“See less”按钮时,在上述步骤中添加的第二行图像 将被删除,并且“See less”按钮将被删除 。
问题:我怎样才能让这个本是一个无限循环,这里的“查看更多”按钮,然后将第3步后重新出现,从而使重复?jQuery:点击时显示,点击时隐藏,无限循环
这里是jQuery的:
$(document).ready(function() {
//Hides the new row to prepare for click event
$('.images-section').children('.new-row').hide();
//Creating variables for see more/less buttons
var more = $('.images-button-more');
var less = $('.images-button-less');
less.hide();
//Add new row on click of see more button
more.on('click', function() {
$('.images-section').children('.new-row').show(function() {
$(this).insertAfter('.old-row').slideDown('1000');
more.fadeOut('slow', function() {
less.insertAfter(more).fadeIn('slow');
});
});
});
//Remove new row on click of see less button
less.on('click', function() {
$('.new-row').slideUp('1000', function() {
less.fadeOut('slow');
});
});
});
这里的HTML:
<section class="no-padding remove-tablet">
<div class="container-fluid images-section">
<div class="row no-gutter old-row">
<div class="col-lg-2 col-sm-6">
<img src="img/ant-johns.jpg" class="img-responsive" alt="Ant Johns" width="317px" height="322px">
</div>
<div class="col-lg-2 col-sm-6">
<img src="img/white-guy.jpg" class="img-responsive" alt="Arnold Jr" width="317px" height="322px">
</div>
<div class="col-lg-2 col-sm-6">
<img src="img/enrique-double-bi.jpg" class="img-responsive" alt="Enrique Double Bi" width="317px" height="322px">
</div>
<div class="col-lg-2 col-sm-6">
<img src="img/anthony-b.jpg" class="img-responsive" alt="Anthony B" width="317px" height="322px">
</div>
<div class="col-lg-2 col-sm-6">
<img src="img/manny-most-muscular.jpg" class="img-responsive" alt="Manny Most Muscular" width="317px" height="322px">
</div>
<div class="col-lg-2 col-sm-6">
<img src="img/remi-model-tats.jpg" class="img-responsive" alt="Remi Model Tats" width="317px" height="322px">
</div>
</div>
<div class="row no-gutter new-row">
<div class="col-lg-2 col-sm-6">
<img src="img/ant-johns.jpg" class="img-responsive" alt="Ant Johns" width="317px" height="322px">
</div>
<div class="col-lg-2 col-sm-6">
<img src="img/white-guy.jpg" class="img-responsive" alt="Arnold Jr" width="317px" height="322px">
</div>
<div class="col-lg-2 col-sm-6">
<img src="img/enrique-double-bi.jpg" class="img-responsive" alt="Enrique Double Bi" width="317px" height="322px">
</div>
<div class="col-lg-2 col-sm-6">
<img src="img/anthony-b.jpg" class="img-responsive" alt="Anthony B" width="317px" height="322px">
</div>
<div class="col-lg-2 col-sm-6">
<img src="img/manny-most-muscular.jpg" class="img-responsive" alt="Manny Most Muscular" width="317px" height="322px">
</div>
<div class="col-lg-2 col-sm-6">
<img src="img/remi-model-tats.jpg" class="img-responsive" alt="Remi Model Tats" width="317px" height="322px">
</div>
</div>
<div class="row">
<div class="col-sm-12 text-center">
<a class="images-button-more" style="padding-bottom: 3px; border-bottom: 1px dotted rgb(130,181,65); position: relative; top: 5px; cursor: pointer; text-decoration: none; border-radius: 50%">See more</a>
</div>
<div class="col-sm-12 text-center">
<a class="images-button-less" style="padding-bottom: 3px; border-bottom: 1px dotted rgb(130,181,65); position: relative; top: 5px; cursor: pointer; text-decoration: none; border-radius: 50%">See less</a>
</div>
</div>
</div>
</section>
我试图把jQuery的周围的if语句,并把像 “isClosed,isNotClosed” 新的变量,然后改变他们的值从0到1基于某些事件和循环,如果isClosed是真实的,但这并没有对我有任何正义。
也请添加html – depperm
添加html =) – Lansana