Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
body { margin: 0; background: #DCD1B4; overflow: hidden; } .ball { position: absolute; transform: translateX(-50%) translateY(-50%); border-radius: 50%; } .face { position: absolute; z-index: -1; width: 40px; height: 40px; background: RGBA(255, 255, 255, 0.5); border-radius: 50%; transform: translateX(-50%) translateY(-50%); } .face .eye { width: 5px; height: 5px; background: RGBA(0, 0, 0, 0.5); position: absolute; top: 40%; } .face .eye.right { right: 20%; } .face .eye.left { right: 60%; } .face .mouth { position: absolute; width: 10%; height: 2px; background: RGBA(0, 0, 0, 0.5); top: 70%; left: 50%; } .smoke { position: absolute; transform: translateX(-50%) translateY(-50%); background: white; border-radius: 50%; z-index: 100; }
JavaScript
var BALL_COUNT=[10,20]; var BALL_SIZE=[5,75]; var BALL_COLORS=[ '#5E9FA3', '#FAB87F', '#F87E7B', '#B05574', ]; var BALL_SPEED=[0.5,1.25]; var BALL_PUSH=1; var BALL_ACCURACY=0.25; // % var PLAYER_SPEED=0.5; var SMOKE_COUNT=[3,5]; var SMOKE_MULTIPLIER=0.2; var SMOKE_SPEED=[5,10]; var SMOKE_SIZE=[19,34]; var SMOKE_FRICTION=0.92; var SMOKE_FADE_SPEED=0.035; var SMOKE_SPREAD=0.45; var SMOKE_TIMER_LIMIT=10; var player; var balls=[]; var smoke=[]; var mouse={ x:window.innerWidth/2, y:window.innerHeight/2 } // Create a ball function createBall() { var el,obj,x,y,size,color; var accuracy=getRandom(-BALL_ACCURACY*100,BALL_ACCURACY*100)/100; // Create the element el=$('
'); // Create the object obj={ el:el, x:getRandom(0,window.innerWidth), y:getRandom(0,window.innerHeight), size:getRandom(BALL_SIZE[0],BALL_SIZE[1]), color:BALL_COLORS[Math.floor( getRandom(0,BALL_COLORS.length) )], xvel:0, yvel:0, speed:getRandom( BALL_SPEED[0]*100, BALL_SPEED[1]*100 )/100, smokeTimer:0, misAim:accuracy } // Style the element el.css({ left:obj.x, top:obj.y, width:obj.size, height:obj.size, background:obj.color, }) // Add to the list of balls balls.push(obj); // Injection $('body').append(el); } // Generate the balls var count=getRandom(BALL_COUNT[0],BALL_COUNT[1]); for (var i=0;i
=SMOKE_TIMER_LIMIT) { createSmoke( v.x+Math.cos(angle+Math.PI)*v.size/2, v.y+Math.sin(angle+Math.PI)*v.size/2, angle+Math.PI, (v.xvel+v.yvel) ) v.smokeTimer=0; } } // Boundaries if (v.x-v.size/2<0) { v.x=v.size/2+1; } else if (v.x+v.size/2 >window.innerWidth) { v.x=window.innerWidth-v.size/2-1; } if (v.y-v.size/2<0) { v.y=v.size/2+1; } else if (v.y+v.size/2>window.innerHeight) { v.y=window.innerHeight-v.size/2-1; } // Style the element v.el.css({ left:v.x, top:v.y }) } } // Create the player function createPlayer() { player={ el:$('.face'), x:window.innerWidth/2, y:window.innerHeight/2, xvel:0, yvel:0, speed:PLAYER_SPEED, scaleX:1, } player.size=player.el.css('width'); player.size=player.size.substring(0,2); } createPlayer(); // Update the player function updatePlayer() { var eyeDistance=5; var angle=Math.atan2((mouse.y-player.y),(mouse.x-player.x)); // Movement player.x+=player.xvel; player.y+=player.yvel; player.xvel+=Math.cos(angle)*player.speed; player.yvel+=Math.sin(angle)*player.speed; player.xvel*=0.99; player.yvel*=0.99; // Boundaries if (player.x-player.size/2<0) { player.x=player.size/2+1; player.xvel*=0.5; createSmoke(player.x-player.size/2,player.y,0,player.xvel); } else if (player.x+player.size/2>window.innerWidth) { player.x=window.innerWidth-player.size/2-1; player.xvel*=-0.5; createSmoke(player.x+player.size/2,player.y,Math.PI,player.xvel); } if (player.y-player.size/2<0) { player.y=player.size/2+1; player.yvel*=-0.5; createSmoke(player.x,player.y-player.size/2,Math.PI/2,player.yvel); } else if (player.y+player.size/2>window.innerHeight) { player.y=window.innerHeight-player.size/2-1; player.yvel*=-0.5; createSmoke(player.x,player.y+player.size/2,-Math.PI/2,player.yvel); } // Facing the mouse if (mouse.x>player.x) { player.scaleX=1; } else { player.scaleX=-1; } // Looking at the mouse var eyes=$('.eye'); var eyeX=Math.cos(angle)*eyeDistance; var eyeY=Math.sin(angle)*eyeDistance; var multiplier=(mouse.x
"); // Variables var vel=SMOKE_MULTIPLIER*Math.abs(speed); var size=getRandom(SMOKE_SIZE[0]*100,SMOKE_SIZE[1]*100)/100*vel; var speed=getRandom(SMOKE_SPEED[0],SMOKE_SPEED[1])*vel var dir=angle+getRandom(-SMOKE_SPREAD*1000,SMOKE_SPREAD*1000)/1000; // Styles el.css({ left:x, top:y, width:size, height:size }) // Object smoke.push({ el:el, x:x, y:y, vel:speed, dir:dir, size:size, alpha:1 }) // Injection $('body').append(el); } // Generate the smoke var count=getRandom(SMOKE_COUNT[0],SMOKE_COUNT[1]); for (var i=0;i
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>鼠标跟随-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号