【问题标题】:Animate Background Color JQuery动画背景颜色 JQuery
【发布时间】:2023-03-11 17:54:01
【问题描述】:

在网上搜索后,似乎有多种方法可以通过 jquery 为颜色设置动画。

对我来说,将“包装”的背景颜色从 #FFF 设置为 #000 的最佳方式是什么?

 var open = true;
    $(".btn-slide").click(function(){ 
        if(open){
        $("#wrapper").animate({
            width: 900,  
            }, 
            1000, function() {
        });
    open= false;
    }else{
        $("#wrapper").animate({
            width: 250,  
            }, 
            1000, function() {
    open = true; }
});

感谢您的建议。非常感谢您的意见。

【问题讨论】:

标签: jquery jquery-animate background-color


【解决方案1】:

你会使用 jQuery animate

然而,jQuery 默认无法插入颜色,因此您需要使用color animation plugin 或(如 Niklas 所述)jQuery UI Effects

【讨论】:

  • @Niklas 确实将其添加到了答案中。
  • 谢谢完美。但是,我将答案归因于@Run,因为它们也提供了语法。谢谢。
【解决方案2】:

你可以试试这个

var open = true; 
        $(".btn-slide").click(function(){ 
        if(open){ 
        $("#wrapper").animate({ 
        width: 900, 
        backgroundColor: '#000' 
        }, 
        1000, function() { 
        }); 
        open= false; 
        }else{ 
        $("#wrapper").animate({ 
        width: 250,
        backgroundColor: '#000' 
        }, 
        1000, function() { 
        open = true; } 
        }); 

【讨论】:

  • 你可以使用toggle()代替open变量操作
  • 感谢 @Run 提供正确的语法。
猜你喜欢
  • 2010-09-16
  • 1970-01-01
  • 1970-01-01
  • 2010-11-20
  • 1970-01-01
  • 1970-01-01
  • 2015-08-11
  • 1970-01-01
  • 2020-11-04
相关资源
最近更新 更多