【问题标题】:Body Background Changer?身体背景改变?
【发布时间】:2012-09-15 09:34:30
【问题描述】:

好的,就是这样。

简单地说,我希望能够通过 CSS 淡出身体的背景,并经常改变,然后循环。

有什么想法可以用 CSS 和 jQuery 实现吗?

谢谢!

【问题讨论】:

    标签: javascript jquery css background document-body


    【解决方案1】:

    您可以使用 jquery animate 方法,并在它完成时使用新颜色再次调用该方法:

    var color = ["red","green","blue"];
    var i = 0;
    
    function changeColor()
    {
     // Change to the next color over 2 seconds.  When it is done, call this method again.
     $("body").animate({"background-color":color[i]}, 2000, changeColor); 
     i++;  // Increment the counter so the next color in the array is shown
     i = i % 3;   // Make sure i is never greater than 2 by using the modulous.
    }
    
    changeColor();
    

    看到这个小提琴:http://jsfiddle.net/johnkoer/vDCSw/5/

    【讨论】:

    • 太棒了!但是我将如何使用背景图像呢?非常感谢!
    • 您必须使用一个 div,然后通过一些交叉淡入淡出为图像设置动画。有关更多信息,请参阅此答案:stackoverflow.com/q/4630947/573218
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-10
    • 1970-01-01
    • 2012-12-16
    相关资源
    最近更新 更多