canvas 點選產生放射性效果
下面的程式碼實現了點選頁面的任何一個位置都會產生放射性效果的功能。
程式碼例項如下:
[HTML] 純文字檢視 複製程式碼執行程式碼<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> <style type="text/css"> .bg { background: #000; overflow: hidden; } </style> </head> <body class="bg"> <canvas id="canvas-club"></canvas> <script> var c = document.getElementById("canvas-club"); var ctx = c.getContext("2d"); var w = c.width = window.innerWidth; var h = c.height = window.innerHeight; var clearColor = 'rgba(0, 0, 0, .1)'; function Rippling() {} Rippling.prototype = { init: function(posX, posY) { this.x = posX; this.y = posY; this.w = 3; this.h = 2; this.vw = 1; this.vh = 1; this.a = 1; this.va = .96; }, draw: function() { ctx.beginPath(); ctx.moveTo(this.x, this.y - this.h / 2); ctx.bezierCurveTo( this.x + this.w / 2, this.y - this.h / 2, this.x + this.w / 2, this.y + this.h / 2, this.x, this.y + this.h / 2); ctx.bezierCurveTo( this.x - this.w / 2, this.y + this.h / 2, this.x - this.w / 2, this.y - this.h / 2, this.x, this.y - this.h / 2); ctx.strokeStyle = 'hsla(180, 100%, 50%, ' + this.a + ')'; ctx.stroke(); ctx.closePath(); this.update(); }, update: function() { if (this.a > .03) { this.w += this.vw; this.h += this.vh; if (this.w > 1) { this.a *= this.va; this.vw *= .98; this.vh *= .98; } } else { ctx.clearRect(0, 0, c.width, c.height); return false; } } }; function anim() { ctx.fillStyle = clearColor; ctx.fillRect(0, 0, w, h); r.draw(); requestAnimationFrame(anim); }; var r = new Rippling(); window.onclick = function(event) { function getMousePos(event) { var e = event || window.event; var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft; var scrollY = document.documentElement.scrollTop || document.body.scrollTop; var x = e.pageX || e.clientX + scrollX; var y = e.pageY || e.clientY + scrollY; return { 'x': x, 'y': y }; } r.init(getMousePos().x, getMousePos().y); } anim(); </script> </body> </html>
相關文章
- canvas實現點選產生放射性效果程式碼例項Canvas
- 直播系統程式碼,點選產生動畫效果並移動的特效動畫特效
- Input元件無點選效果元件
- Android Button 點選效果Android
- Item點選水波紋效果
- canvas小球碰壁效果Canvas
- canvas矩形拖拽效果Canvas
- canvas簽名效果Canvas
- RecyclerView點選新增波紋效果View
- javascript點選燃放煙火效果JavaScript
- 設定點選效果foreground
- CSS去除移動端點選時元素產生的背景色CSS
- iOS 中tableview cell點選取消選中效果iOSView
- 服裝生產管理軟體鞋帽生產系統的優點
- canvas繪製流星效果Canvas
- canvas實現波浪效果Canvas
- canvas小球擺動效果Canvas
- canvas蔚藍星空效果Canvas
- 點選返回網頁頂層效果網頁
- winphone系統a、input標籤被點選時產生的半透明灰色背景
- JavaScript點選按鈕彈出層效果JavaScript
- iOS 實現點選微信頭像效果iOS
- JavaScript點選投票效果程式碼例項JavaScript
- 網頁點選實現下載效果網頁
- Jetapck Compose 去除點選水波紋效果
- canvas設定陰影效果Canvas
- canvas圓形時鐘效果Canvas
- canvas繪製風車效果Canvas
- canvas小球落地彈動效果Canvas
- canvas環形資料效果Canvas
- canvas簡單畫板效果Canvas
- canvas畫布效果程式碼Canvas
- canvas動態時鐘效果Canvas
- canvas立體效果的圓環Canvas
- canvas卡通形象笑臉效果Canvas
- 真·生產力「GitHub 熱點速覽」Github
- 化工企業的生產經營特點與ERP軟體選型(轉)
- 點選文字框實現文字框內容選中效果