使用jQuery/css淡出背景图像

Fading background images with jQuery/css?

本文关键字:背景 图像 淡出 css jQuery 使用      更新时间:2023-09-26

我有下面的脚本(从这里开始),它加载一个图像并将其设置为背景。它工作得很好,但我需要更改什么才能添加多张照片,使其成为幻灯片?

jQuery:

$(document).ready(function(){
    $.fn.smartBackgroundImage = function(url){
        var t = this;
        //create an img so the browser will download the image:
        $('<img />')
        .attr('src', url)
        .load(function(){ //attach onload to set background-image
                t.each(function(){ 
                $(this).css('backgroundImage', 'url('+url+')' );
                });
            });
        return this;
    }
    $('body').smartBackgroundImage('/static/images/temp-bg.jpg');
});

谢谢

使用<li>标记将图像合并到html中,并使用jquery对其进行格式化。因此以后更容易更改它们。