JavaScript 캔버스는 회전 애니메이션을 구현합니다.
Jan 18, 2018 am 11:28 AM
canvas
javascript
js
이 글에서는 회전 애니메이션을 구체적으로 구현하기 위한 JavaScript 캔버스를 주로 소개합니다. 관심 있는 친구들이 참고하면 도움이 될 것입니다.
캔버스의 캔버스를 사용하여 회전 애니메이션을 구현합니다. 외부 원은 시계 방향, 내부 레이어는 시계 반대 방향입니다.
코드 데모 링크 주소: 코드 데모 링크 주소
html 파일
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <style> body { margin: 0; padding: 0; overflow: hidden; background-color: #f0f0f0; } </style> <script src="js/konva.js"></script> <script src="js/circle.js"></script> </head> <body> <p id="cas"></p> <script> var width = window.innerWidth; var height = window.innerHeight; //创建舞台 var stage = new Konva.Stage({ container: "cas", width: width, height: height }); //创建层 var layer = new Konva.Layer(); //创建组1 var group = new Konva.Group({ x: stage.width() / 2, y: stage.height() / 2, }); //最外层圆 var circle1 = new Konva.Circle({ x: 0, y: 0, radius: 250, stroke: "#ccc", strokeWidth: 1, dash: [6, 3] }); group.add(circle1); //第二个圆 var circle2 = new Konva.Circle({ x: 0, y: 0, radius: 150, stroke: "#ccc", strokeWidth: 1, dash: [6, 3] }); group.add(circle2); //第三个圆 var circle3 = new Konva.Circle({ x: 0, y: 0, radius: 135, stroke: "blue", strokeWidth: 2, dash: [10, 5] }); group.add(circle3); //第四个圆 var circle4 = new Konva.Circle({ x: 0, y: 0, radius: 105, fill: "#ccc", opacity: 0.4 }); group.add(circle4); //第五个圆 var circle5 = new Konva.Circle({ x: 0, y: 0, radius: 80, fill: "#74A2F0" }); group.add(circle5); //添加文字 var text = new Konva.Text({ x: -80, y: -12, text: "WEB全栈", fill: "white", fontSize: 24, width: 160, align: "center" }); group.add(text); layer.add(group); //***************************************************** //创建组2 var outGroup = new Konva.Group({ x: stage.width() / 2, y: stage.height() / 2, }); var arrColor = ["red", "green", "blue", "orange", "purple"]; var arrText = ["web", "node.js", "ajax", "html5", "css"]; for(var i = 0; i < 5; i++) { var cir = new Circle({ x : 250 * Math.cos(72 * i * Math.PI / 180), //圆心x轴的坐标 y : 250 * Math.sin(72 * i * Math.PI / 180), //圆心y轴的坐标 outR : 60, //外圆的半径 inR : 50, //内圆的半径 fill : arrColor[i], //填充颜色 text: arrText[i], //文字 outOpacity : 0.3, //外圆的透明度 inOpacity : 0.6 //内圆的透明度 }); cir.drawCircle(outGroup); } layer.add(outGroup); //*********************************************** //创建组3 var inGroup = new Konva.Group({ x: stage.width() / 2, y: stage.height() / 2, }); var arrColor = ["red", "green", "blue", "orange", "purple"]; var arrText = ["web", "node.js", "ajax", "html5", "css"]; for(var i = 0; i < 5; i++) { var cir = new Circle({ x : 135 * Math.cos(90 * i * Math.PI / 180), //圆心x轴的坐标 y : 135 * Math.sin(90 * i * Math.PI / 180), //圆心y轴的坐标 outR : 45, //外圆的半径 inR : 35, //内圆的半径 fill : arrColor[i], //填充颜色 text: arrText[i], //文字 outOpacity : 0.3, //外圆的透明度 inOpacity : 0.6 //内圆的透明度 }); cir.drawCircle(inGroup); } layer.add(inGroup); //************************************************ //运动动画 var step = 1; //转动的角度 var anim = new Konva.Animation(function() { outGroup.rotate(step); outGroup.getChildren().each(function (ele, index) { ele.rotate(-step); }); inGroup.rotate(-step); inGroup.getChildren().each(function (ele, index) { ele.rotate(step); }); }, layer); anim.start(); stage.add(layer); stage.on("mouseover", function () { step = 0.3; }); stage.on("mouseout", function () { step = 1; }); </script> </body> </html>
로그인 후 복사
js 파일
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); } }
로그인 후 복사
효과 그림:
관련 권장 사항:
3D 그림 큐브 회전 애니메이션 특수 효과를 구현하는 순수 CSS3
HTML5/CSS3 3D 큐브 회전 애니메이션 클래식 케이스
간단하다 CSS 회전 애니메이션 효과 구현 예제에 대한 자세한 설명
위 내용은 JavaScript 캔버스는 회전 애니메이션을 구현합니다.의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

인기 기사
Repo : 팀원을 부활시키는 방법
3 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
1 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
스플릿 소설을이기는 데 얼마나 걸립니까?
3 몇 주 전
By DDD
헬로 키티 아일랜드 어드벤처 : 거대한 씨앗을 얻는 방법
3 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌

인기 기사
Repo : 팀원을 부활시키는 방법
3 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
1 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
스플릿 소설을이기는 데 얼마나 걸립니까?
3 몇 주 전
By DDD
헬로 키티 아일랜드 어드벤처 : 거대한 씨앗을 얻는 방법
3 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌

뜨거운 기사 태그

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제
Gmail 이메일의 로그인 입구는 어디에 있나요?
7296
9


자바 튜토리얼
1622
14


Cakephp 튜토리얼
1342
46


라라벨 튜토리얼
1259
25


PHP 튜토리얼
1206
29



간단한 JavaScript 튜토리얼: HTTP 상태 코드를 얻는 방법

캔버스 프레임워크를 배우고 일반적으로 사용되는 캔버스 프레임워크에 대해 자세히 설명합니다.
