jQuery 简单的背景滑块循环

jQuery simple Background slider loop

我需要自动更改背景图片或通过单击滑块来更改。它需要在 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();功能来实现这一点。

希望对您有所帮助。

您可以像这样使用 setTimeout() 函数:

setInterval(function(){
  $('#container').css('background-image', 'url(https://static.pexels.com/photos/36487/above-adventure-aerial-air.jpg)')
;}, 3000);

https://jsfiddle.net/srjdyyLd/1/