檢查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