我想学习Java脚本动画,我发现在这个网站真的很好的例子:http://javascript.info/tutorial/animation#maths-the-function-of-progress-delta简单的动画
但问题是,作为一个初学者,我不明白是怎么功能和对象相互配合。
问题01
我复制的例子“让我们在上面创建的基本运动动画:”但我的版本不工作。
<!DOCTYPE HTML>
<html>
<head>
<style>
.example_path{
position: relative;
width: 600px;
height: 100px;
border-style: solid;
border-width: 5px;
}
.example_block{
position: absolute;
width: 100px;
height: 100px;
background-color: yellow;
}
</style>
</head>
<body>
<div onclick="move(this.children[0])" class="example_path">
<div class="example_block"></div>
</div>
<script>
function move(element, delta, duration) {
var to = 500
animate({
delay: 10,
duration: duration || 1000, // 1 sec by default
delta: delta,
step: function(delta) {
element.style.left = to*delta + "px"
}
})
}
</script>
</body>
</html>
输出控制台:的ReferenceError:动画是没有定义 有谁知道问题是什么?
问题02
我的第二个愿望是,整合easeInOut功能
function makeEaseInOut(delta) {
return function(progress) {
if (progress < .5)
return delta(2*progress)/2
else
return (2 - delta(2*(1-progress)))/2
}
}
bounceEaseInOut = makeEaseInOut(bounce)
如何链接这两个代码段?代码也是从这个页面:http://javascript.info/tutorial/animation#maths-the-function-of-progress-delta
你错过http://javascript.info/files/tutorial/browser/animation/animate.js –
他们进一步定义动画功能的页面中你联系,你只需在你的代码中缺少它。 – spaceman