我刚开始使用 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.3
和 1.9.1
。删除不需要的。
关于javascript - Velocity.js 中的动画颜色变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31372051/