gpt4 book ai didi

Jquery,背景颜色过渡循环

转载 作者:行者123 更新时间:2023-12-01 07:34:26 24 4
gpt4 key购买 nike

我希望对背景颜色进行动画处理,以便它在各种预定义颜色之间无限循环。

我不是程序员,对 jquery 很陌生,如果有人能帮助我解决这个问题,我将非常感激

谢谢!

最佳答案

基于 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 .

关于Jquery,背景颜色过渡循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3597175/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com