Home  >  Article  >  Web Front-end  >  JavaScript canvas implements rotation animation

JavaScript canvas implements rotation animation

小云云
小云云Original
2018-01-18 11:28:372100browse

This article mainly introduces JavaScript canvas to realize rotation animation in detail. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.

Use the canvas of canvas to realize the rotation animation, the outer circle is clockwise, and the inner layer is counterclockwise

Code demo link address:Code demo link address

html file


 
 
 
  
  
  
  
  

js file


function Circle(obj) { 
 this._init(obj); 
} 
Circle.prototype = { 
 _init: function (obj) { 
  this.x = obj.x, //圆心x轴的坐标 
  this.y = obj.y, //圆心y轴的坐标 
  this.outR = obj.outR, //外圆的半径 
  this.inR = obj.inR, //内圆的半径 
  this.color = obj.fill, //填充颜色 
  this.text = obj.text, //内圆的文字 
  this.outOpacity = obj.outOpacity, //外圆的透明度 
  this.inOpacity = obj.inOpacity  //内圆的透明度 
 }, 
 drawCircle: function (group) { 
  //创建一个组 
  var groupCir = new Konva.Group({ 
   x: this.x, 
   y: this.y 
  }); 
  //外圆 
  var outCir = new Konva.Circle({ 
   x: 0, 
   y: 0, 
   radius: this.outR, 
   fill: this.color, 
   opacity: this.outOpacity 
  }); 
  groupCir.add(outCir); 
  //内圆 
  var inCir = new Konva.Circle({ 
   x: 0, 
   y: 0, 
   radius: this.inR, 
   fill: this.color, 
   opacity: this.inOpacity 
  }); 
  groupCir.add(inCir); 
  //添加文字 
  var text = new Konva.Text({ 
   x: -this.inR, 
   y: -10, 
   text: this.text, 
   fill: "white", 
   fontSize: 20, 
   width: 2 * this.inR, 
   align: "center" 
  }); 
  groupCir.add(text); 
 
  group.add(groupCir); 
 } 
}

Effect picture:

Related recommendations:

Pure css3 to realize 3D picture cube rotation animation special effects

HTML5/CSS3 3D cube rotation animation classic Case

Detailed explanation of a simple implementation example of css rotation animation effect

The above is the detailed content of JavaScript canvas implements rotation animation. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn