整合營銷服務商

          電腦端+手機端+微信端=數據同步管理

          免費咨詢熱線:

          HTML5的裝逼法寶之-鼠標特效

          這個用戶體驗為王的時代,有各種酷炫主流的畫面操作,毫無疑問是非常重要的,今天我們就來實現鼠標特效——火焰

          代碼實現:

          <html>
          <head>
          <meta charset="utf-8">
          <title>HTML5 Canvas火焰跟隨鼠標動畫DEMO演示</title>
          <style>
          html, body {
          	margin:0;
          	padding:0;
          	height: 100%;
          }
          </style>
          </head>
          <body>
          <div style="text-align:center;clear:both;">
          <script src="/gg_bd_ad_720x90.js" type="text/javascript"></script>
          <script src="/follow.js" type="text/javascript"></script>
          </div>
          <canvas id="fire"></canvas>
          <script>
          var Fire = function(){
          	this.canvas 		= document.getElementById('fire');
          	this.ctx 			= this.canvas.getContext('2d');
          	this.canvas.height 	= window.innerHeight;
          	this.canvas.width 	= window.innerWidth;
          	this.aFires 		= [];
          	this.aSpark 		= [];
          	this.aSpark2 		= [];
          	this.mouse = {
          		x : this.canvas.width * .5,
          		y : this.canvas.height * .75,
          	}
          	this.init();
          }
          Fire.prototype.init = function()
          {
          	
          	this.canvas.addEventListener('mousemove', this.updateMouse.bind( this ), false);
          }
          Fire.prototype.run = function(){
          	
          	this.update();
          	this.draw();
          	if( this.bRuning )
          		requestAnimationFrame( this.run.bind( this ) );
          }
          Fire.prototype.start = function(){
          	this.bRuning = true;
          	this.run();
          }
          Fire.prototype.stop = function(){
          	this.bRuning = false;
          }
          Fire.prototype.update = function(){
          	this.aFires.push( new Flame( this.mouse ) );
          	this.aSpark.push( new Spark( this.mouse ) );
          	this.aSpark2.push( new Spark( this.mouse ) );
          	for (var i = this.aFires.length - 1; i >= 0; i--) {
          		if( this.aFires[i].alive )
          			this.aFires[i].update();
          		else
          			this.aFires.splice( i, 1 );
          	}
          	for (var i = this.aSpark.length - 1; i >= 0; i--) {
          		if( this.aSpark[i].alive )
          			this.aSpark[i].update();
          		else
          			this.aSpark.splice( i, 1 );
          	}
          	for (var i = this.aSpark2.length - 1; i >= 0; i--) {
          		if( this.aSpark2[i].alive )
          			this.aSpark2[i].update();
          		else
          			this.aSpark2.splice( i, 1 );
          	}
          }
          Fire.prototype.draw = function(){
          	this.ctx.globalCompositeOperation = "source-over";
          	this.ctx.fillStyle = "rgba( 15, 5, 2, 1 )";
          	this.ctx.fillRect( 0, 0, window.innerWidth, window.innerHeight );
          	
          	this.grd = this.ctx.createRadialGradient( this.mouse.x, this.mouse.y - 200,200,this.mouse.x, this.mouse.y - 100,0 );
          	this.grd.addColorStop(0,"rgb( 15, 5, 2 )");
          	this.grd.addColorStop(1,"rgb( 30, 10, 2 )");
          	this.ctx.beginPath();
          	this.ctx.arc( this.mouse.x, this.mouse.y - 100, 200, 0, 2*Math.PI );
          	this.ctx.fillStyle= this.grd;
          	this.ctx.fill();
          	
          	this.ctx.font = "15em Amatic SC";
          	this.ctx.textAlign = "center";
          	this.ctx.strokeStyle = "rgb(50, 20, 0)";
          	this.ctx.fillStyle = "rgb(120, 10, 0)";
          	this.ctx.lineWidth = 2;
          	this.ctx.strokeText("Fire",this.canvas.width/2, this.canvas.height * .72 );
          	this.ctx.fillText("Fire",this.canvas.width/2, this.canvas.height * .72 );	
          	this.ctx.globalCompositeOperation = "overlay";//or lighter or soft-light
          	for (var i = this.aFires.length - 1; i >= 0; i--) {
          		this.aFires[i].draw( this.ctx );
          	}
          	this.ctx.globalCompositeOperation = "soft-light";//"soft-light";//"color-dodge";
          	for (var i = this.aSpark.length - 1; i >= 0; i--) {
          		
          		if( ( i % 2 ) === 0 )
          			this.aSpark[i].draw( this.ctx );
          	}
          	this.ctx.globalCompositeOperation = "color-dodge";//"soft-light";//"color-dodge";
          	for (var i = this.aSpark2.length - 1; i >= 0; i--) {
          		this.aSpark2[i].draw( this.ctx );
          	}
          }
          Fire.prototype.updateMouse = function( e ){
          	this.mouse.x = e.clientX;
          	this.mouse.y = e.clientY;
          	//this.aFires.push( new Flame( this.mouse ) );
          }
          var Flame = function( mouse ){
          	this.cx = mouse.x;
          	this.cy = mouse.y;
          	this.x = rand( this.cx - 25, this.cx + 25);
          	this.y = rand( this.cy - 5, this.cy + 5);
          	this.vy = rand( 1, 3 );
          	this.vx = rand( -1, 1 );
          	this.r = rand( 20, 30 );
          	this.life = rand( 3, 6 );
          	this.alive = true;
          	this.c = {
          		h : Math.floor( rand( 2, 40) ),
          		s : 100,
          		l : rand( 80, 100 ),
          		a : 0,
          		ta : rand( 0.8, 0.9 )
          	}
          }
          Flame.prototype.update = function()
          {
          	this.y -= this.vy;
          	this.vy += 0.05;
          	this.x += this.vx;
          	if( this.x < this.cx )
          		this.vx += 0.1;
          	else
          		this.vx -= 0.1;
          	if( this.r > 0 )
          		this.r -= 0.1;
          	
          	if( this.r <= 0 )
          		this.r = 0;
          	this.life -= 0.15;
          	if( this.life <= 0 ){
          		this.c.a -= 0.05;
          		if( this.c.a <= 0 )
          			this.alive = false;
          	}else if( this.life > 0 && this.c.a < this.c.ta ){
          		this.c.a += .08;
          	}
          }
          Flame.prototype.draw = function( ctx ){
          	ctx.beginPath();
          	ctx.arc( this.x, this.y, this.r * 3, 0, 2*Math.PI );
          	ctx.fillStyle = "hsla( " + this.c.h + ", " + this.c.s + "%, " + this.c.l + "%, " + (this.c.a/20) + ")";
          	ctx.fill();
          	ctx.beginPath();
          	ctx.arc( this.x, this.y, this.r, 0, 2*Math.PI );
          	ctx.fillStyle = "hsla( " + this.c.h + ", " + this.c.s + "%, " + this.c.l + "%, " + this.c.a + ")";
          	ctx.fill();
          }
          var Spark = function( mouse ){
          	this.cx = mouse.x;
          	this.cy = mouse.y;
          	this.x = rand( this.cx -40, this.cx + 40);
          	this.y = rand( this.cy, this.cy + 5);
          	this.lx = this.x;
          	this.ly = this.y;
          	this.vy = rand( 1, 3 );
          	this.vx = rand( -4, 4 );
          	this.r = rand( 0, 1 );
          	this.life = rand( 4, 5 );
          	this.alive = true;
          	this.c = {
          		h : Math.floor( rand( 2, 40) ),
          		s : 100,
          		l : rand( 40, 100 ),
          		a : rand( 0.8, 0.9 )
          	}
          }
          Spark.prototype.update = function()
          {
          	this.lx = this.x;
          	this.ly = this.y;
          	this.y -= this.vy;
          	this.x += this.vx;
          	if( this.x < this.cx )
          		this.vx += 0.2;
          	else
          		this.vx -= 0.2;
          	this.vy += 0.08;
          	this.life -= 0.1;
          	if( this.life <= 0 ){
          		this.c.a -= 0.05;
          		if( this.c.a <= 0 )
          			this.alive = false;
          	}
          }
          Spark.prototype.draw = function( ctx ){
          	ctx.beginPath();
          	ctx.moveTo( this.lx , this.ly);
          	ctx.lineTo( this.x, this.y);
          	ctx.strokeStyle = "hsla( " + this.c.h + ", " + this.c.s + "%, " + this.c.l + "%, " + (this.c.a / 2) + ")";
          	ctx.lineWidth = this.r * 2;
          	ctx.lineCap = 'round';
          	ctx.stroke();
          	ctx.closePath();
          	ctx.beginPath();
          	ctx.moveTo( this.lx , this.ly);
          	ctx.lineTo( this.x, this.y);
          	ctx.strokeStyle = "hsla( " + this.c.h + ", " + this.c.s + "%, " + this.c.l + "%, " + this.c.a + ")";
          	ctx.lineWidth = this.r;
          	ctx.stroke();
          	ctx.closePath();
          }
          rand = function( min, max ){ return Math.random() * ( max - min) + min; };
          onresize = function () { oCanvas.canvas.width = window.innerWidth; oCanvas.canvas.height = window.innerHeight; };
          var oCanvas;
          init = function()
          {
          	oCanvas = new Fire();
          	oCanvas.start();
          }
          window.onload = init;
          </script>
          </body>
          </html>
          

          學習從來不是一個人的事情,要有個相互監督的伙伴,想要學習或交流前端問題的小伙伴可以私信回復小明“學習” 獲取前端學習資料,一起學習!

          用css3制作鼠標滑過內容上移特效,運用到CSS3的動畫過渡屬性

          前后對比圖!

          實現代碼:

          家好,今天給大家介紹一款, 網頁響應鼠標滾動特效代碼html前端源碼(圖1)。送給大家哦,獲取方式在本文末尾。

          圖1

          每滾動向下一次鼠標,文字和圖片都會發生變化,類似一些數碼產品新品發布網頁的效果,看起來非??犰牛▓D2)

          圖2

          向上滾動鼠標,圖片和文字就會還原(圖3)

          圖3

          源碼完整,需要的朋友可以下載學習(圖4)

          圖4

          本源碼編碼:10180,需要的朋友,點擊下面的鏈接后,搜索10180,即可獲取。

          就愛UI - 分享UI設計的點點滴滴


          主站蜘蛛池模板: 一区二区三区视频观看| 一区二区三区四区视频在线| 在线观看一区二区三区av| 国产一区二区三区在线观看影院| 国产精品一区二区av不卡| 日韩一区二区在线免费观看| 精品无码一区二区三区爱欲| 国产一区二区在线|播放| 国产电影一区二区| 中文字幕人妻丝袜乱一区三区| 国产精品亚洲一区二区三区| 日韩欧美一区二区三区免费观看| 亚洲一区二区电影| 久久99精品一区二区三区| 亚洲综合国产一区二区三区| 亚洲人AV永久一区二区三区久久| 波多野结衣中文一区| 国产伦精品一区二区三区免费下载| 亚洲.国产.欧美一区二区三区 | 亚洲乱码一区二区三区在线观看 | 精品91一区二区三区| 久久青青草原一区二区| 男人的天堂av亚洲一区2区| 制服丝袜一区在线| 国产福利微拍精品一区二区| 自拍日韩亚洲一区在线| 午夜影院一区二区| 色欲AV蜜桃一区二区三| 在线日韩麻豆一区| 国产日韩精品一区二区在线观看播放| 日韩美一区二区三区| 福利在线一区二区| 日韩精品无码一区二区三区AV| 中文字幕在线精品视频入口一区| 鲁丝片一区二区三区免费| 亚洲国产精品第一区二区| 无码国产精品一区二区免费式直播 | 日本一区二区不卡视频| 少妇精品久久久一区二区三区| 精品无码AV一区二区三区不卡| 精品国产一区二区三区不卡|