日期:2014-05-16 浏览次数:20382 次
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> <script type="text/javascript" src="kineticjs.js"></script> </head> <body> <div id="content"></div> </body> <script> (function(){ var load = function(){ var stage = new Kinetic.Stage({ container: "content", width: 578, height: 200 }); var drawCurves = function(){ var context = this.getContext(); var layer = this.getLayer(); var quad = layer.quad; context.beginPath(); context.moveTo(quad.start[0], quad.start[1]); context.quadraticCurveTo(quad.control[0], quad.control[1], quad.end[0], quad.end[1]); context.strokeStyle = "red"; context.lineWidth = 4; context.stroke(); context.fill(); }; //创造一个Canvas,可以想象为一个图层 var layer = new Kinetic.Layer({ drawFunc: drawCurves }); layer.quad = { start: [60, 30], control: [240, 110], end: [80, 160] }; (function(){ //图层内的一个画画对象 var shape = new Kinetic.Shape({ //points: [layer.quad.start[0], layer.quad.start[1], layer.quad.control[0], layer.quad.control[1], layer.quad.end[0], layer.quad.end[1]], fill: "red", drawFunc: drawCurves, alpha: 0 }); shape.on("mousemove", function() { }); layer.add(shape); })(); stage.add(layer); }; load(); })(); </script> </html>