目录

JqueryUI - Color 动画 Animation

jQueryUI扩展了一些核心jQuery方法,以便您可以为元素设置不同的过渡动画。 其中一个是animate方法。 jQueryUI扩展了jQuery animate方法,以添加对动画颜色的支持。 您可以为定义元素颜色的多个CSS属性中的一个设置动画。 以下是animate方法支持的CSS属性。

  • backgroundColor - 设置元素的背景颜色。

  • borderTopColor - 设置元素边框顶部的颜色。

  • borderBottomColor - 设置元素边框底部的颜色。

  • borderLeftColor - 设置元素边框左侧的颜色。

  • borderRightColor - 设置元素边框右侧的颜色。

  • color - 设置元素的文本颜色。

  • outlineColor - 设置轮廓的颜色; 用来强调元素。

语法 (Syntax)

以下是jQueryUI animate方法的语法 -

$( "#selector" ).animate(
   { backgroundColor: "black",
      color: "white"
   }
);

您可以在此方法中设置任意数量的属性,以(逗号)分隔。

例子 (Example)

以下示例演示了addClass()方法的用法。

<!DOCTYPE html>
<html>
   <head>
      <meta charset = "utf-8">
      <title>jQuery UI addClass Example</title>
      <link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
         rel = "stylesheet">
      <script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
      <script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
      <style>
         .elemClass {
            width: 200px;
            height: 50px;
            background-color: #b9cd6d;
         }
         .myClass {
            font-size: 40px; background-color: #ccc; color: white;
         }
      </style>
      <script type = "text/javascript">
         $(document).ready(function() {
            $('#button-1').click(function() {
               $('#animTarget').animate({
                  backgroundColor: "black",
                  color: "white"
               })
            })
         });
      </script>
   </head>
   <body>
      <div id = animTarget class = "elemClass">
         Hello!
      </div>
      <button id = "button-1">Click Me</button>
   </body>
</html>

让我们将上述代码保存在HTML文件animateexample.htm ,并在支持javascript的标准浏览器中打开它,您还必须看到以下输出。 现在,你可以玩结果 -

新页面打开

单击按钮,查看动画如何更改框。

↑回到顶部↑
WIKI教程 @2018