即時通訊試圖讓圖像被放置在側div所以h/w可以控制,我似乎得到它與jQuery 3.2.1的工作它只適用於jQuery 2.1.1 ,有沒有更好的方式來編寫這段代碼,我試圖通過簡單的點擊「下一個」div來改變圖像。圖像數組循環JS CSS
$(function() {
var images = [
"http://placehold.it/300x150/f0f&text=1"
,"http://placehold.it/300x150/cf5&text=2"
,"http://placehold.it/300x150/b15&text=3"
,"http://placehold.it/300x150/c59&text=4"
,"http://placehold.it/300x150/ac2&text=5"
,"http://placehold.it/300x150/bb5&text=6"
];
// ======================================
var tot = images.length;
var c = 0; // current image
function loadImage(){
$("<img/>").attr("src",images[c]).load(function() {
$('#gallery').html(this);
});
}
loadImage(); // for the page load
$('#prev').click(function(){
id=this; c--;
c=c==-1?tot-1:c%tot;
loadImage();
});
$('#next').click(function(){
id=this; c++;
c=c==-1?tot-1:c%tot;
loadImage();
});
});
#gallery{
width:150px;
height:50px;
background:#ddd;
margin-top:8px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="pagination">
<div id="prev" class="btn" style="position:">PREV</div>
<div id="next" class="btn" style="position:">NEXT</div>
</div>
<div id="gallery">
</div>
什麼是問題與問題'javascript'? – guest271314
圖像對於libs的最新視覺是不可見的。 – evanrochon
請參閱https://stackoverflow.com/questions/37738732/jquery-3-0-url-indexof-error/ – guest271314