您的位置:首页 > Web前端 > JavaScript

HTML5里面的一个知识:Canvas二层与KineticJS完成事件!

2013-09-25 19:52 567 查看
触发一个用户定义函数当二层与KineticJS结束,我们可以设置onFinish进行。

代码的确写得挺好的,下面呢,我也不说其它的啦,直接上代码给大家看:



<!DOCTYPE HTML>
<html>
<head>
<style>
body {
margin: 0px;
padding: 0px;
}
</style>
</head>
<body>
<div id="container"></div>
<script src="http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v4.7.1.min.js"></script>
<script defer="defer">
function writeMessage(message) {
text.setText(message);
layer.draw();
}

var stage = new Kinetic.Stage({
container: 'container',
width: 578,
height: 200
});

var layer = new Kinetic.Layer();

var text = new Kinetic.Text({
x: 10,
y: 10,
fontFamily: 'Calibri',
fontSize: 24,
text: '',
fill: 'black'
});

var wheel = new Kinetic.Star({
x: stage.getWidth() / 2,
y: stage.getHeight() / 2,
numPoints: 50,
outerRadius: 70,
innerRadius: 50,
fill: 'purple',
stroke: 'black',
strokeWidth: 5,
lineJoin: 'bevel'
});

layer.add(wheel);
layer.add(text);
stage.add(layer);

var tween = new Kinetic.Tween({
node: wheel,
duration: 4,
rotation: Math.PI * 2,
easing: Kinetic.Easings.BackEaseOut,
onFinish: function() {
writeMessage('tween finished!');
}
});

setTimeout(function() {
tween.play();
}, 1000);

</script>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息