javascript - Velocity.js 中的动画颜色变化

标签 javascript jquery svg jquery-animate velocity.js

我刚开始使用 Velocity.js 并尝试制作一个简单的动画,我将圆的颜色从红色更改为黄色。我的 HTML 只是...

<!DOCTYPE html>
<html>
<head>
  <link href="https://code.jquery.com/ui/1.9.2/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />
  <script src="https://code.jquery.com/jquery-1.8.3.min.js"></script>
  <script src="https://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
  <script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
  <script src="//cdn.jsdelivr.net/velocity/1.2.2/velocity.min.js"></script>
  <script src="//cdn.jsdelivr.net/velocity/1.2.2/velocity.ui.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <svg height=300 width=300>
    <circle id="example" cx=50 cy=50 r=20 fill="red"></circle>
  </svg>
</body>
</html>

...我正在尝试在我的 JavaScript 中将圆圈的颜色更改为黄色:

$('#example')
   .delay(1000)
   .velocity({fill: "yellow"});

我做错了什么?

最佳答案

根据 velocity.js docs ,您需要将填充颜色值作为十六进制字符串传递:

片段:

$('#example').delay(1000).velocity({ fill: '#ffff00' }, { duration: 2000 });
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.9.0/jquery-ui.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/velocity/1.2.2/velocity.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/velocity/1.2.2/velocity.ui.min.js"></script>
<svg height=300 width=300>
    <circle id="example" cx=50 cy=50 r=20 fill="red"></circle>
</svg>

希望这对您有所帮助。

附言您正在尝试加载多个 jQuery 版本,即 1.8.31.9.1。删除不需要的。

关于javascript - Velocity.js 中的动画颜色变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31372051/

相关文章:

css - 为什么 Chrome 会剪辑我的高度 : 100% SVG when I zoom out

javascript - jQuery 中的 attr() 是否强制小写?

css - SVG Rect 忽略高度?

javascript - 悬停时淡入背景图像

javascript - 将 html 内容更改为所选选项

jquery - 使用 Jquery 的圆 Angular 插件时要包含哪些 .js 文件?

javascript - 弹出窗口中的浮线图具有重叠的轴标签

嵌入在参数中的 Javascript 函数自动运行?

javascript - 在 Javascript 中,如何判断用户是否同时按下两个键?

javascript - 根据输入值默认选择选项