我喜欢使用 click 以任何所需的角度旋转画布中的文本,但这里的文本是顺时针和 anticloclwise 旋转的。我喜欢顺时针旋转它到我想要的角度。
代码:
<html>
<head>
<style>
body { margin: 0px; padding: 0px; }
canvas { border: 1px solid #9C9898; }
</style>
<script src="http://www.html5canvastutorials.com/libraries/kinetic-0.2.js">
</script>
<script>
window.onload = function() {
var angle = 0;
var stage = new Kinetic.Stage({
container: "container",
width: 578,
height: 200
});
var layer = new Kinetic.Layer();
var text = new Kinetic.Text({
x:225,
y: 80,
text: "Simple",
fontSize: 30,
fontFamily: "Calibri",
textFill: "black",
draggable: true
});
text.on("click", function(){
angle=getRandomInt(1,4);
text.transitionTo({
rotation:Math.PI*angle/2,
duration:1
});
});
layer.add(text);
stage.add(layer);
}
function getRandomInt (min, max) {
return (Math.random() * (max - min + 1)) + min;
}
</script>
</head>
<body>
<div id="container"></div>
</body>
</html>