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
- jQuery點選滑出層效果程式碼例項jQuery
- canvas原型鐘錶效果程式碼例項Canvas原型
- canvas氣泡上浮效果程式碼例項Canvas
- canvas繪製箭頭效果程式碼例項Canvas
- jQuery tab選項卡效果程式碼例項jQuery
- html實現簡單ListViews效果的例項程式碼HTMLView
- canvas刮刮樂程式碼例項Canvas
- canvas繪製扇形程式碼例項Canvas
- canvas繪製網格程式碼例項Canvas
- CSS橢圓效果程式碼例項CSS
- JavaScript 點選複製選中文字程式碼例項JavaScript
- 直播系統程式碼,點選產生動畫效果並移動的特效動畫特效
- JavaScript實現選項卡效果JavaScript
- canvas繪製機器貓程式碼例項Canvas
- canvas繪製拋物線程式碼例項Canvas線程
- canvas translate()、scale()和rotate()方法程式碼例項Canvas
- Canvas實現放大鏡效果完整案例分析(附程式碼)Canvas
- 美化滾動條效果程式碼例項
- css3水滴效果程式碼例項CSSS3
- css背景虛化效果程式碼例項CSS
- jQuery點選文字框清除內容程式碼例項jQuery
- canvas繪製圓形鐘錶程式碼例項Canvas
- canvas實現波浪效果Canvas
- 純css tab選項卡程式碼例項CSS
- css3晃動效果程式碼例項CSSS3
- CSS3心形效果程式碼例項CSSS3
- div前後翻轉效果程式碼例項
- 當前文字框高亮效果程式碼例項
- CSS3旋轉效果程式碼例項CSSS3
- 淡入淡出效果簡單程式碼例項
- html5 canvas 實現光線沿不規則路徑運動例項程式碼HTMLCanvas
- CSS3滑過光束效果程式碼例項CSSS3
- CSS3小黃人效果程式碼例項CSSS3
- css3折角效果程式碼例項CSSS3
- CSS3梯形效果程式碼例項CSSS3
- CSS3背景漸變效果程式碼例項CSSS3
- CSS3星系運動效果程式碼例項CSSS3
- vuejs實現新增tag標籤程式碼例項VueJS