我想知道在画布中添加文本后,如何使用鼠标单击将文本旋转到我喜欢的任何动态角度?这是一个例子:
<html>
<head>
<style>
body { margin: 0px; padding: 0px; }
canvas { border: 1px solid #9C9898; }
</style>
<script src="http://www.html5canvastutorials.com/libraries/kinetic-v3.10.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"
});
text.on("click", function(){
angle+=1
text.transitionTo({
rotation:Math.PI*angle/2,
duration:1
});
});
layer.add(text);
stage.add(layer);
}
</script>
</head>
<body>
<div id="container"></div>
</body>
</html>
这里使用鼠标单击,每次单击鼠标时它都会旋转 45 度,但我想将文本旋转到任何所需的角度。