您的位置 首页 > 娱乐休闲

HTML5漂亮的Canvas鼠标箭头跟随动画特效 鼠标如何变成箭头

更多特效代码请添加HTML5前端交流群581549454

废话不多说,上代码!

网站格式代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ";>

<html xmlns=";>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<style type="text/css">

* { margin:0; padding:0; }

body { position:relative; width:100%; height:100%; overflow:hidden; }

button { color:#222; font-size:20px; padding:5px 20px; width:120px; }

#btn1 { position:absolute; top:10px; left:10px; }

#btn2 { position:absolute; top:60px; left:10px; }

#btn3 { position:absolute; top:110px; left:10px; }

#btn4 { position:absolute; top:160px; left:10px; }

#btn5 { position:absolute; top:210px; left:10px; }

#btn6 { position:absolute; top:260px; left:10px; }

#btn7 { position:absolute; top:310px; left:10px; }

#btn8 { position:absolute; top:360px; left:10px; }

#btn9 { position:absolute; top:410px; left:10px; }

#btn0 { position:absolute; top:460px; left:10px; }

</style>

<script src="j;></script>

<title>漂亮的canvas鼠标箭头跟随动画特效</title>

</head>

<body><script src="/demo;></script>

<canvas id="c"></canvas>

<div class="btn_left;">

<button id="btn1">效果1</button>

<button id="btn2">效果2</button>

<button id="btn3">效果3</button>

<button id="btn4">效果4</button>

<button id="btn5">效果5</button>

<button id="btn6">效果6</button>

<button id="btn7">效果7</button>

<button id="btn8">效果8</button>

<button id="btn9">效果9</button>

<button id="btn0">效果10</button>

</div>

<script type="text/javascript">

$(document).ready(function() {

var canvas = document.getElementById("c");

var ctx = canvas.getContext("2d");

var c = $("#c");

var x,y,w,h,cx,cy,l;

var y = [];

var b = {

n:100,

c:false, // 颜色 如果是false 则是随机渐变颜色

bc:'#000', // 背景颜色

r:0.9,

o:0.05,

a:1,

s:20,

}

var bx = 0,by = 0,vx = 0,vy = 0;

var td = 0;

var p = 0;

var hs = 0;

re();

var color,color2;

i){

color2 = b.c;

}else{

color = Ma()*360;

}

$(window).resize(function(){

re();

});

var tp1=true,tp2 = false,tp3 = false,tp4 = false,tp5 = false,tp6 = false,tp7 = false,tp8 = false,tp9 = false,tp0 = false;

function begin(){

if(tp1){

if(!b.c){

color+=.1;

color2 = 'hsl('+color+',100%,80%)';

}

c = 1;

c = b.bc;

c(0,0,w,h);

for(var i=0;i<y.length;i++){

c = y[i].o;

c = color2;

c();

c(y[i].x,y[i].y,y[i].r,0,Ma*2);

c();

c();

y[i].r+=b.r;

y[i].o-=b.o;

if(y[i].o<=0){

y.splice(i,1);

i--;

};

}

}else if(tp2){

if(!b.c){

color+=.1;

color2 = 'hsl('+color+',100%,80%)';

}

c = 1;

c = b.bc;

c(0,0,w,h);

for(var i=0;i<y.length;i++){

c = y[i].o;

c = color2;

c();

y[i].r=10;

c;

c;

c(y[i].x,y[i].y,y[i].r,0,Ma*2);

c();

c();

c;

y[i].o-=b.o;

y[i].v+=b.a;

y[i].y+=y[i].v;

if(y[i].y>=h+y[i].r || y[i].o<=0){

y.splice(i,1);

i--;

};

}

}else if(tp3){

if(!b.c){

color+=.1;

color2 = 'hsl('+color+',100%,80%)';

}

td+=5;

c = 1;

c = b.bc;

c(0,0,w,h);

for(var i=0;i<y.length;i++){

c = y[i].o;

c = color2;

c();

c;

c;

y[i].r=(1-(y[i].y/h))*20;

c(y[i].x,y[i].y,y[i].r,0,Ma*2);

c();

c();

c;

y[i].o=y[i].y/h;

y[i].v+=b.a;

y[i].y-=b.s;

y[i].x+=((y[i].y+td)/100)*10);

if(y[i].y<=0-y[i].r || y[i].o<=0){

y.splice(i,1);

i--;

};

}

}else if(tp4){

if(!b.c){

color+=.1;

color2 = 'hsl('+color+',100%,80%)';

}

c = 1;

c = b.bc;

c(0,0,w,h);

for(var i=0;i<y.length;i++){

c = y[i].o;

c = color2;

c();

c;

c;

y[i].vx2 += (cx - y[i].wx)/1000;

y[i].vy2 += (cy - y[i].wy)/1000;

y[i].wx+=y[i].vx2;

y[i].wy+=y[i].vy2;

y[i].o-=b.o/2;

y[i].r=10;

c(y[i].wx,y[i].wy,y[i].r,0,Ma*2);

c();

c();

c;

if(y[i].o<=0){

y.splice(i,1);

i--;

};

}

}else if(tp5){

if(!b.c){

color+=.1;

color2 = 'hsl('+color+',100%,80%)';

}

c = .18;

c = b.bc;

c(0,0,w,h);

p+=5;

c = 1;

c = color2;

c();

c;

c;

c(cx+50*Ma(p*Ma/180),cy+50*Ma(p*Ma/180),10,0,Ma*2);

c();

c();

c();

c(cx+50*Ma((p+180)*Ma/180),cy+50*Ma((p+180)*Ma/180),10,0,Ma*2);

c();

c();

c();

c(cx+50*Ma((p+90)*Ma/180),cy+50*Ma((p+90)*Ma/180),10,0,Ma*2);

c();

c();

c();

c(cx+50*Ma((p+270)*Ma/180),cy+50*Ma((p+270)*Ma/180),10,0,Ma*2);

c();

c();

c;

}else if(tp6){

if(!b.c){

color+=.1;

color2 = 'hsl('+color+',100%,80%)';

}

c = 0.2;

c = b.bc;

c(0,0,w,h);

for(var i=0;i<y.length;i++){

c = y[i].o;

c = color2;

c();

c = 2;

c(y[i].x,y[i].y);

c((y[i].wx+y[i].x)/2+Ma()*20,(y[i].wy+y[i].y)/2+Ma()*20);

c(y[i].wx,y[i].wy);

c();

c();

y[i].o-=b.o;

if(y[i].o<=0){

y.splice(i,1);

i--;

};

}

}else if(tp7){

if(!b.c){

color+=.1;

color2 = 'hsl('+color+',100%,80%)';

}

c = 0.2;

c = b.bc;

c(0,0,w,h);

i;b.n*2){

hs = Ma()*2*Ma;

y.push({x:cx+((Ma)*100*Ma(hs)),y:cy+((Ma)*100*Ma(hs)),o:1,h:hs});

}

for(var i=0;i<y.length;i++){

c = y[i].o;

c = color2;

c();

y[i].x+=(cx-y[i].x)/10;

y[i].y+=(cy-y[i].y)/10;

c(y[i].x,y[i].y,1,0,Ma*2);

c();

c();

y[i].o-=b.o;

if(y[i].o<=0){

y[i].h = Ma()*2*Ma;

y[i].x = cx+((Ma)*100*Ma(y[i].h));

y[i].y = cy+((Ma)*100*Ma(y[i].h));

y[i].o = 1;

};

}

}else if(tp8){

if(!b.c){

color+=.1;

color2 = 'hsl('+color+',100%,80%)';

}

c = 0.2;

c = b.bc;

c(0,0,w,h);

c = color2;

if(cx%4 == 0){

cx+=1;

}else if(cx%4 == 2){

cx-=1

}

else if(cx%4 == 3){

cx-=2

}

if(cy%4 == 0){

cy+=1;

}else if(cy%4 == 2){

cy-=1

}

else if(cy%4 == 3){

cy-=2

}

for(var i=cx-60;i<cx+60;i+=4){

for(var j=cy-60;j<cy+60;j+=4){

i(cx-i,2)+Ma(cy-j,2))<=60){

c = 1-(cx-i,2)+Ma(cy-j,2))/60);

if(Ma()<.2){

c(i,j,3,3);

}

}

}

}

}else if(tp9){

if(!b.c){

color+=.1;

color2 = 'hsl('+color+',100%,80%)';

}

c = 0.2;

c = b.bc;

c(0,0,w,h);

c = color2;

if(cx%4 == 0){

cx+=1;

}else if(cx%4 == 2){

cx-=1

}

else if(cx%4 == 3){

cx-=2

}

if(cy%4 == 0){

cy+=1;

}else if(cy%4 == 2){

cy-=1

}

else if(cy%4 == 3){

cy-=2

}

i;b.n){

y.push({x:cx,y:cy,xv:0,yv:0,o:1});

}

for(var i=0;i<y.length;i++){

if(y[i].xv==0 && y[i].yv==0){

if(Ma()<.5){

if(Ma()<.5){

y[i].xv = 3;

}else{

y[i].xv = -3;

}

}else{

if(Ma()<.5){

y[i].yv = 3;

}else{

y[i].yv = -3;

}

}

}else{

if(y[i].xv == 0){

if(Ma()<.66){

y[i].yv = 0;

if(Ma()<.5){

y[i].xv = 3;

}else{

y[i].xv = -3;

}

}

}else if(y[i].yv == 0){

if(Ma()<.66){

y[i].xv = 0;

if(Ma()<.5){

y[i].yv = 3;

}else{

y[i].yv = -3;

}

}

}

}

y[i].o-=b.o/2;

c = y[i].o;

y[i].x+=y[i].xv;

y[i].y+=y[i].yv;

c(y[i].x,y[i].y,3,3);

if(y[i].o<=0){

y.splice(i,1);

i--;

};

}

}else if(tp0){

if(!b.c){

color+=.1;

color2 = 'hsl('+color+',100%,80%)';

}

c = 0.2;

c = b.bc;

c(0,0,w,h);

c = color2;

y.push({x:cx,y:cy,xv:2,yv:1,o:1});

for(var i=0;i<y.length;i++){

y[i].o-=b.o/10;

c = y[i].o;

y[i].x+=(Ma)*4;

y[i].y-=1;

c(y[i].x,y[i].y,2,2);

if(y[i].o<=0){

y.splice(i,1);

i--;

};

}

}

window.requestAnimationFrame(begin);

}

function re(){

w = window.innerWidth;

h = window.innerHeight;

canvas.width = w;

canvas.height = h;

cx = w/2;

cy = h/2;

};

c.mousemove(function(e){

cx = e.().left;

cy = e.().top;

if(tp4){

if(Ma()<=.5){

if(Ma()<=.5){

bx = -10;

}else{

bx = w+10;

}

by = Ma()*h;

}else{

if(Ma()<=.5){

by = -10;

}else{

by = h+10;

}

bx = Ma()*w;

}

vx = (Ma)*8;

vy = (Ma)*8;

}

if(tp1 || tp2 || tp3){

y.push({x:cx,y:cy,r:b.r,o:1,v:0});

}else if(tp4){

y.push({x:cx,y:cy,r:b.r,o:1,v:0,wx:bx,wy:by,vx2:vx,vy2:vy});

}else if(tp6){

y.push({x:cx+((Ma)*30),y:cy+((Ma)*30),o:1,wx:cx,wy:cy});

}

});

/*c.mousedown(function(){

c.on('mousemove',function(e){

cx = e.().left;

cy = e.().top;

y.push({x:cx,y:cy,r:b.r,o:1});

});

c.on('mouseup',function(){

c.off('mouseup');

c.off('mousemove');

c.off('moseleave');

});

c.on('mouseleave',function(){

c.off('mouseup');

c.off('mousemove');

c.off('moseleave');

});

});*/

$("#btn1").click(function(){

tp1 = true;

tp2 = false;

tp3 = false;

tp4 = false;

tp5 = false;

tp6 = false;

tp7 = false;

tp8 = false;

tp9 = false;

tp0 = false;

y=[];

});

$("#btn2").click(function(){

tp1 = false;

tp2 = true;

tp3 = false;

tp4 = false;

tp5 = false;

tp6 = false;

tp7 = false;

tp8 = false;

tp9 = false;

tp0 = false;

y=[];

});

$("#btn3").click(function(){

tp1 = false;

tp2 = false;

tp3 = true;

tp4 = false;

tp5 = false;

tp6 = false;

tp7 = false;

tp8 = false;

tp9 = false;

tp0 = false;

y=[];

});

$("#btn4").click(function(){

tp1 = false;

tp2 = false;

tp3 = false;

tp4 = true;

tp5 = false;

tp6 = false;

tp7 = false;

tp8 = false;

tp9 = false;

tp0 = false;

y=[];

});

$("#btn5").click(function(){

tp1 = false;

tp2 = false;

tp3 = false;

tp4 = false;

tp5 = true;

tp6 = false;

tp7 = false;

tp8 = false;

tp9 = false;

tp0 = false;

y=[];

});

$("#btn6").click(function(){

tp1 = false;

tp2 = false;

tp3 = false;

tp4 = false;

tp5 = false;

tp6 = true;

tp7 = false;

tp8 = false;

tp9 = false;

tp0 = false;

y=[];

});

$("#btn7").click(function(){

tp1 = false;

tp2 = false;

tp3 = false;

tp4 = false;

tp5 = false;

tp6 = false;

tp7 = true;

tp8 = false;

tp9 = false;

tp0 = false;

y=[];

});

$("#btn8").click(function(){

tp1 = false;

tp2 = false;

tp3 = false;

tp4 = false;

tp5 = false;

tp6 = false;

tp7 = false;

tp8 = true;

tp9 = false;

tp0 = false;

y=[];

});

$("#btn9").click(function(){

tp1 = false;

tp2 = false;

tp3 = false;

tp4 = false;

tp5 = false;

tp6 = false;

tp7 = false;

tp8 = false;

tp9 = true;

tp0 = false;

y=[];

});

$("#btn0").click(function(){

tp1 = false;

tp2 = false;

tp3 = false;

tp4 = false;

tp5 = false;

tp6 = false;

tp7 = false;

tp8 = false;

tp9 = false;

tp0 = true;

y=[];

});

(function() {

var lastTime = 0;

var vendors = ['webkit', 'moz'];

for(var xx = 0; xx < vendors.length && !window.requestAnimationFrame; ++xx) {

window.requestAnimationFrame = window[vendors[xx] + 'RequestAnimationFrame'];

window.cancelAnimationFrame = window[vendors[xx] + 'CancelAnimationFrame'] ||

window[vendors[xx] + 'CancelRequestAnimationFrame'];

}

if (!window.requestAnimationFrame) {

window.requestAnimationFrame = function(callback, element) {

var currTime = new Date().getTime();

var timeToCall = Ma(0, 16.7 - (currTime - lastTime));

var id = window.setTimeout(function() {

callback(currTime + timeToCall);

}, timeToCall);

lastTime = currTime + timeToCall;

return id;

};

}

if (!window.cancelAnimationFrame) {

window.cancelAnimationFrame = function(id) {

clearTimeout(id);

};

}

}());

begin();

});

</script>

</body>

</html>

JS代码过多没有在这里展示,大家可在群内查找

责任编辑: 鲁达

1.内容基于多重复合算法人工智能语言模型创作,旨在以深度学习研究为目的传播信息知识,内容观点与本网站无关,反馈举报请
2.仅供读者参考,本网站未对该内容进行证实,对其原创性、真实性、完整性、及时性不作任何保证;
3.本站属于非营利性站点无毒无广告,请读者放心使用!

“如何把鼠标箭头美化,如何设置鼠标箭头,如何隐藏鼠标箭头,如何显示鼠标箭头”边界阅读