相關(guān)關(guān)鍵詞
關(guān)于我們
最新文章
- ThinkPHP 5.1、6.0、6.1 與 8.0 版本對(duì)比分析
- 涉嫌侵權(quán)的人只復(fù)制了版權(quán)軟件,沒有傳播給其他人,是否符合復(fù)制侵權(quán)的判定?
- 網(wǎng)站域名備案到企業(yè)名下后,即表明是商業(yè)使用了嗎?
- 軟件中使用了GPL & MIT 協(xié)議的文件 和 使用了 GPL | MIT 的有什么區(qū)別?
- 網(wǎng)站版權(quán)糾紛中的來源非法是否有嚴(yán)格的司法定義?
- [確定有效] ECSHOP后臺(tái)登錄不了的問題解決 https打不開
- 免費(fèi)搜索代碼:如何利用百度做一個(gè)企業(yè)網(wǎng)站內(nèi)搜索?
- MySQL 中 HAVING 與 REPLACE 的用法解析
- 深入理解 MySQL 的連接操作:-h、-P、-u、-p 詳解
- 在 MySQL Workbench 中自定義導(dǎo)出文件格式的解決方案
html5使用canvas實(shí)現(xiàn)跟隨光標(biāo)跳動(dòng)的火焰效果
本效果的完整代碼如下,把代碼保存到HTML文件中打開也能查看效果,火焰會(huì)跟隨光標(biāo):
復(fù)制代碼
代碼如下:<!DOCTYPE HTML>
<head>
<meta charset=utf-8" />
<title>HTML5 Canvas火焰效果</title>
<style type="text/css">
body{margin: 0; padding: 0;}
#canvas-keleyi-com {display: block;}
</style>
</head>
<body>
<canvas id="canvas-keleyi-com"></canvas>
<script type="text/javascript">
window.onload = function(){
var keleyi_canvas = document.getElementById("canvas-kel"+"eyi-com");
var ctx = keleyi_canvas.getContext("2d");
var W = window.innerWidth, H = window.innerHeight;
keleyi_canvas.width = W;
keleyi_canvas.height = H;</p> <p>var particles = [];
var mouse = {};</p> <p>//Lets create some particles now
var particle_count = 100;
for(var i = 0; i < particle_count; i++)
{
particles.push(new particle());
}
keleyi_canvas.addEventListener('mousemove', track_mouse, false);</p> <p>function track_mouse(e)
{
mouse.x = e.pageX;
mouse.y = e.pageY;
}</p> <p>function particle()
{
this.speed = {x: -2.5+Math.random()*5, y: -15+Math.random()*10};
//location = mouse coordinates
//Now the flame follows the mouse coordinates
if(mouse.x && mouse.y)
{
this.location = {x: mouse.x, y: mouse.y};
}
else
{
this.location = {x: W/2, y: H/2};
}
//radius range = 10-30
this.radius = 10+Math.random()*20;
//life range = 20-30
this.life = 20+Math.random()*10;
this.remaining_life = this.life;
//colors
this.r = Math.round(Math.random()*255);
this.g = Math.round(Math.random()*255);
this.b = Math.round(Math.random()*255);
}</p> <p>function draw()
{
ctx.globalCompositeOperation = "source-over";
ctx.fillStyle = "black";
ctx.fillRect(0, 0, W, H);
ctx.globalCompositeOperation = "lighter";</p> <p>for(var i = 0; i < particles.length; i++)
{
var p = particles[i];
ctx.beginPath();
p.opacity = Math.round(p.remaining_life/p.life*100)/100
var gradient = ctx.createRadialGradient(p.location.x, p.location.y, 0, p.location.x, p.location.y, p.radius);
gradient.addColorStop(0, "rgba("+p.r+", "+p.g+", "+p.b+", "+p.opacity+")");
gradient.addColorStop(0.5, "rgba("+p.r+", "+p.g+", "+p.b+", "+p.opacity+")");
gradient.addColorStop(1, "rgba("+p.r+", "+p.g+", "+p.b+", 0)");
ctx.fillStyle = gradient;
ctx.arc(p.location.x, p.location.y, p.radius, Math.PI*2, false);
ctx.fill();</p> <p>
p.remaining_life--;
p.radius--;
p.location.x += p.speed.x;
p.location.y += p.speed.y;</p> <p>if(p.remaining_life < 0 || p.radius < 0)
{
particles[i] = new particle();
}
}
}</p> <p>setInterval(draw, 86);
}
</script>
</body>
</html>
相關(guān)文章
- win7 64位 IIS7 IIS7.5 無法連接Access數(shù)據(jù)庫的問題解決
- 基于jQuery的上下無縫滾動(dòng)應(yīng)用(單行或多行)
- htaccess轉(zhuǎn)換httpd.ini方法及案例參考
- 網(wǎng)站偽靜態(tài)的優(yōu)缺點(diǎn)
- 高質(zhì)量的外部鏈接從何而來?
- SEO不能忽視外鏈建設(shè),更加要注重內(nèi)鏈建設(shè)
- 如何挑選合適的虛擬主機(jī)
- 網(wǎng)站建設(shè)的五個(gè)誤區(qū)
- php header 404跳轉(zhuǎn)錯(cuò)誤頁面的寫法
- 網(wǎng)頁嵌入百度地圖實(shí)例