我爲我的數組實現了一個迭代器,但我需要將array[i]
作爲div元素的背景圖像。我的迭代過程完成,但背景圖像不起作用。任何專家能解決這個問題嗎如何通過setInterval設置div元素的圖像背景?
//var imgobj = ['https://www.w3.org/html/logo/downloads/HTML5_Logo_512.png','https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTWOZVcvYs5dunAY_vSMxvFNKOvLWbn3RkHUM8SEU1cci9kNJEG','http://www.adservio.fr/img/logos2/jquery.jpg','https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcSKaIDe-P2BzZgWQLEOBo-LOTqduyPmBaRKhh0XcNG64fOTsm9e9A','http://www.unixstickers.com/image/data/stickers/python/python.sh.png'];
var imgobj1 = ['IMG1', 'IMG2', 'IMG3', 'IMG4', 'IMG5'];
var i = 0;
function iterate() {
setInterval(function() {
$('.frame-div').html(imgobj1[i]);
//$('.frame-div').css({'background',imgobj[i]});
i++
}, 2000);
}
$(document).ready(function() {
iterate();
setInterval(function() {
i = 0;
}, 10000);
});
.frame-div {
width: 300px;
height: 300px;
border: 1px solid #c1dbff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="frame-div"></div>
如果給予適當的圖片網址,將工作imgobj的 – abhiklpm
雅陣列= [------]。 –
我已經給出了正確的URL –