我需要自动更改背景图像或通过单击 slider 元素符号来更改。它需要在 window.load 上设置超时和自动播放。这是我的 fiddle : JSfiddle
<div id="container">
<a href="#" class="changeBG">1</a>
<a href="#" class="changeBG">2</a>
<a href="#" class="changeBG">3</a>
</div>
<style>
#container{
background-image: url(http://www.uniwallpaper.com/static/images/eiffel-tower-wallpaper-18_fRZLW4V.jpg);
width:400px;
height:300px;
}
a{color:#fff;}
</style>
<script>
$('.changeBG').on('click', function() {
$('#container').css('background-image', 'url(https://static.pexels.com/photos/36487/above-adventure-aerial-air.jpg)');
})
// image 3
// http://www.lanlinglaurel.com/data/out/71/4541654-3d-hd-wallpaper.jpg
</script>
最佳答案
您可以像这样使用 setTimeout() 函数:
setInterval(function(){
$('#container').css('background-image', 'url(https://static.pexels.com/photos/36487/above-adventure-aerial-air.jpg)')
;}, 3000);
关于jQuery 简单背景 slider 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42555632/