チェックJsFiddle Demo
ラップする剰余関数を使用します。
click = click % 4;
またはあなたはそれが動的に要素の数を取得したい場合は、代わりにこれを使用することができます:
JsFiddle Demo
click = click % $('.some h1').length;
HTMLを
<div align="center" id="feedTxt">
<div class="some">
<h1>title 1</h1>
<br>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently
with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </p>
</div>
<div class="some">
<h1>title 2</h1>
<br>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently
with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </p>
</div>
<div class="some">
<h1>title 3</h1>
<br>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently
with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </p>
</div>
<div class="some">
<h1>title 4</h1>
<br>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently
with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </p>
</div>
</div>
<button id="SLIDE">Peress to slide</button>
の
JS
var click = 1;
$("#SLIDE").click(function() {
var widths = $('.some').width() * click;
$(".some").first()
.animate({ "margin-left": "-"+widths }, "slow")
.next()
.animate({ "margin-left": 0 }, "slow")
.end();
click+=1;
click = click % $('.some h1').length;
});
CSS
#feedTxt {
display: flex;
overflow-x: scroll;
height:450px;
width:100%;
}
.some {
flex: 0 0 100%;
height: 450px;
}
歓声...これは私が探していた解決策です... – Jackson