【问题标题】:Jquery, Background color transition loopJquery,背景颜色转换循环
【发布时间】:2010-08-30 00:30:45
【问题描述】:

我希望为背景颜色设置动画,以便它在无限循环中循环通过各种预定义颜色。

我不是程序员,也不是 jquery 的新手,如果有人能帮我解决这个问题,我会非常感激 ist

谢谢!

【问题讨论】:

  • 您能发布您已经完成的工作吗?很难准确地说出您需要什么。

标签: jquery gradient transition


【解决方案1】:

以 Byron 的解决方案为基础并利用 color animations plugin

// The array of colours and current index within the colour array
// This array can be hex values or named colours
var colours = ['red', 'orange', 'yellow', 'green', 'blue', 'purple'];
var currIndex = 0;

// The element to animage the background-color of
var elem = $('#element-id');

// Infinitely animate the background-color of your element every second
var loop = setInterval(function(){
    elem.animate({backgroundColor: colours[currIndex++]});

    // Set the current index in the colour array, making sure to loop
    // back to beginning once last colour is reached
    currIndex = currIndex == colours.length ? 0 : currIndex;
}, 1000);

你可以看到in action here

【讨论】:

    【解决方案2】:

    window.setInterval('functionToChangeColour()', 5000);这将每 5000 毫秒运行一次函数,按照您希望的方式更改颜色。

    您可以分配一个对象 var obj = setInterval('functionToChangeColour()', 5000);如果你喜欢使用 window.clearInterval(obj) 来清除间隔

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-08
      • 1970-01-01
      • 2016-05-24
      • 2014-02-23
      • 2012-12-28
      • 1970-01-01
      • 1970-01-01
      • 2015-11-07
      相关资源
      最近更新 更多