Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
Click on me
css
particle { position: fixed; left: 0; top: 0; border-radius: 50%; pointer-events: none; opacity: 0; } button { padding: 10px; } body { overflow: hidden; display: flex; height: 100vh; align-items: center; justify-content: center;background-color: #1D1D1D }
JavaScript
if (document.body.animate) { document.querySelector('#button').addEventListener('click', pop); } function pop (e) { // Quick check if user clicked the button using a keyboard if (e.clientX === 0 && e.clientY === 0) { const bbox = document.querySelector('#button').getBoundingClientRect(); const x = bbox.left + bbox.width / 2; const y = bbox.top + bbox.height / 2; for (let i = 0; i < 30; i++) { // We call the function createParticle 30 times // We pass the coordinates of the button for x & y values createParticle(x, y); } } else { for (let i = 0; i < 30; i++) { // We call the function createParticle 30 times // As we need the coordinates of the mouse, we pass them as arguments createParticle(e.clientX, e.clientY); } } } function createParticle (x, y) { const particle = document.createElement('particle'); document.body.appendChild(particle); // Calculate a random size from 5px to 25px const size = Math.floor(Math.random() * 20 + 5); particle.style.width = `${size}px`; particle.style.height = `${size}px`; // Generate a random color in a blue/purple palette particle.style.background = `hsl(${Math.random() * 90 + 180}, 70%, 60%)`; // Generate a random x & y destination within a distance of 75px from the mouse const destinationX = x + (Math.random() - 0.5) * 2 * 75; const destinationY = y + (Math.random() - 0.5) * 2 * 75; // Store the animation in a variable as we will need it later const animation = particle.animate([ { // Set the origin position of the particle // We offset the particle with half its size to center it around the mouse transform: `translate(-50%, -50%) translate(${x}px, ${y}px)`, opacity: 1 }, { // We define the final coordinates as the second keyframe transform: `translate(${destinationX}px, ${destinationY}px)`, opacity: 0 } ], { // Set a random duration from 500 to 1500ms duration: Math.random() * 1000 + 500, easing: 'cubic-bezier(0, .9, .57, 1)', // Delay every particle with a random value of 200ms delay: Math.random() * 200 }); // When the animation is complete, remove the element from the DOM animation.onfinish = () => { particle.remove(); }; }
粒子
时间
文字
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号