var currentIndex = 0,
items = $('.container div'),
itemAmt = items.length;
function cycleItems() {
var item = $('.container div').eq(currentIndex);
items.hide();
item.css('display','inline-block');
}
var autoSlide = setInterval(function() {
currentIndex += 1;
if (currentIndex > itemAmt - 1) {
currentIndex = 0;
}
cycleItems();
}, 3000);
$('.next').click(function() {
clearInterval(autoSlide);
currentIndex += 1;
if (currentIndex > itemAmt - 1) {
currentIndex = 0;
}
cycleItems();
});
$('.prev').click(function() {
clearInterval(autoSlide);
currentIndex -= 1;
if (currentIndex < 0) {
currentIndex = itemAmt - 1;
}
cycleItems();
});
これは私の他のファイルのjqueryです。このスクリプトをHTMLページから取り込む方法を知っていますか? htmlページでjqueryを呼び出す方法は?
<button class="next">Next</button>
<button class="prev">Previous</button>
<div class="container">
<div style="display: inline-block;">
<img src="http://placeimg.com/400/200/people"/>
</div>
<div>
<img src="http://placeimg.com/400/200/any"/>
</div>
<div>
<img src="http://placeimg.com/400/200/nature"/>
</div>
<div>
<img src="http://placeimg.com/400/200/architecture"/>
</div>
<div>
<img src="http://placeimg.com/400/200/animals"/>
</div>
<div>
<img src="http://placeimg.com/400/200/people"/>
</div>
<div>
<img src="http://placeimg.com/400/200/tech"/>
</div>
</div>
これは私のhtmlファイルであると私は、コードの先頭にスクリプトが含まれています。しかし、接続が作成されていないようですか?私はこれの初心者です。おかげ
「スクリプトタグ」を使用するだけで – Nehal