canvas模擬eharts首頁動畫效果
分享一段程式碼例項,它利用canvas模擬實現了eharts首頁動畫效果。
程式碼例項如下:
[HTML] 純文字檢視 複製程式碼執行程式碼<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> <style> * { margin: 0; padding: 0; } html, body { width: 100%; height: 100%; } body { background: -webkit-linear-gradient(#4f7e9a,#2a3d56); } #sin { display: block; } .wrap { width: 0; height: 200px; position: absolute; bottom: 40px; left: 0; overflow: hidden; animation: kk 2.4s linear forwards; } @keyframes kk { 0% { width: 0; height: 200px; } 100% { width: 100%; height: 200px; } } .shadow { width: 50%; position: absolute; top: 380px; left: -100%; animation: img 1s cubic-bezier(0.665, -0.570, 0.420, 1.650) forwards 1s; } @keyframes img { 0% { left: -100%; transform: translateX(0); } 100% { left: 50%; transform: translateX(-56%); } } #word { display: block; position: absolute; top: 100px; left: 50%; transform: translateX(-50%); animation: hah 1s cubic-bezier(0.665, -0.570, 0.420, 1.650) forwards; } @keyframes hah { 0% { transform: translateX(-50%) scale(.3); } 100% { transform: translateX(-50%) scale(1); } } </style> <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script> </head> <body> <canvas id="word" width="1000" height="200"></canvas> <div class="wrap"> <canvas id="sin" height="200"></canvas> </div> <script> var screenWidth = document.documentElement.clientWidth; $("#sin").attr("width", screenWidth); var line = document.getElementById("sin"); var myCanvas = line.getContext("2d"); myCanvas.lineWidth = 2; myCanvas.strokeStyle = "#fff"; myCanvas.beginPath(); myCanvas.translate(20, 100); myCanvas.moveTo(-100, 50); for (var i = 0; i < 80; i += 0.1) { var x = i * 80 - 40; var y = Math.cos(i) * 50; myCanvas.lineTo(x, y); } myCanvas.stroke(); myCanvas.closePath(); myCanvas.lineWidth = 1; myCanvas.strokeStyle = "rgba(255,255,255,.8)"; myCanvas.beginPath(); myCanvas.translate(15, -30); myCanvas.moveTo(-100, 40); for (var i = -2; i < 80; i += 0.1) { var x = i * 60 - 40; var y = Math.cos(i) * 40; myCanvas.lineTo(x, y); } myCanvas.stroke(); myCanvas.closePath(); myCanvas.strokeStyle = "rgba(255,255,255,.5)"; myCanvas.beginPath(); myCanvas.translate(5, -46); myCanvas.moveTo(-90, 40); for (var i = 0; i < 80; i += 0.1) { var x = i * 46 - 90; var y = Math.cos(i) * 16; myCanvas.lineTo(x, y); } myCanvas.stroke(); myCanvas.closePath(); /* eCharts */ var line2 = document.getElementById("word"); var myCanvas2 = line2.getContext("2d"); var timer = null; var angle = 0; var flag = 0; var $deg = 0; draw(0); timer = setInterval(function() { flag++; if (flag >= 120) { angle--; // console.log(angle); if (angle <= -40) { clearInterval(timer); } $deg = angle * Math.PI / 180; draw($deg); } }, 20); myCanvas2.save(); myCanvas2.font = "150px Arial"; myCanvas2.beginPath(); myCanvas2.translate(210, 120); myCanvas2.strokeStyle = "white"; myCanvas2.fillStyle = "white"; myCanvas2.fillText("charts 3", 30, 30); myCanvas2.stroke(); myCanvas2.fill(); myCanvas2.closePath(); myCanvas2.restore(); function draw(deg) { myCanvas2.save(); myCanvas2.beginPath(); myCanvas2.translate(190, 150); myCanvas2.clearRect(-80, -100, 132, 120); myCanvas2.rotate(deg); //myCanvas2.strokeStyle = "rgba(170,49,77,.95)"; myCanvas2.fillStyle = "rgba(170,49,77,.95)"; myCanvas2.font = "160px Arial"; myCanvas2.fillText("e", -30, 10); //myCanvas2.stroke(); myCanvas2.fill(); myCanvas2.rotate(-deg); myCanvas.closePath(); myCanvas2.restore(); } </script> </body> </html>
相關文章
- canvas模擬彈幕效果程式碼例項Canvas
- 仿噹噹App首頁按鈕漸變動畫效果APP動畫
- css動畫之 360首頁四字移動效果CSS動畫
- 強大的CSS:模擬下雪效果動畫製作教程CSS動畫
- canvas實現簡答動畫張閉嘴效果Canvas動畫
- 純css模擬下雪效果CSS
- JavaScript模擬拋物效果JavaScript
- 攜程前端模擬排序動畫前端排序動畫
- css3和js模擬翻頁效果程式碼例項CSSS3JS
- Web 頁面如何實現動畫效果Web動畫
- HTML5模擬齒輪動畫HTML動畫
- web前端入門到實戰:css3迴圈,模擬拼多多動畫效果Web前端CSSS3動畫
- canvas水球動畫Canvas動畫
- canvas動畫心得Canvas動畫
- JavaScript模擬HashMap類效果程式碼JavaScriptHashMap
- js模擬實現列舉效果JS
- iOS粒子效果模擬器—UIEffectDesigneriOSUI
- 自定義TabBar動畫效果 - 頁面轉場(Swift)tabBar動畫Swift
- 使用UICollectionView實現首頁的滾動效果UIView
- Threejs實現滴滴官網首頁地球動畫JS動畫
- Canvas 實現畫中畫動畫效果--網易娛樂年度盤點H5動畫解密Canvas動畫H5解密
- Canvas 實現畫中畫動畫效果–網易娛樂年度盤點H5動畫解密Canvas動畫H5解密
- iOS仿淘寶詳情頁,支付寶首頁上滑效果iOS
- 網頁小實驗——用canvas生成精靈動畫圖片網頁Canvas動畫
- Flutter實戰動畫番外篇-翻頁效果實現Flutter動畫
- SVG 動畫實現彈性的頁面元素效果SVG動畫
- 分享7款超炫的HTML5 Canvas 3D動畫效果HTMLCanvas3D動畫
- js實現的模擬滾動條效果JS
- JavaScript模擬無重新整理評論效果JavaScript
- 模擬發放紅包效果程式碼例項
- canvas小球碰壁效果Canvas
- canvas矩形拖拽效果Canvas
- canvas簽名效果Canvas
- canvas動畫特效 之 星空Canvas動畫特效
- canvas動畫教程-1 引言Canvas動畫
- Canvas 動畫初體驗Canvas動畫
- jQuery 效果 – 動畫jQuery動畫
- UGUI動畫效果UGUI動畫