Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
css
body { margin: 0; } #app { width: 100vw; height: 100vh; } .star { animation: move 20s linear infinite; } .shootingStar { animation: dash 0.7s ease; } @keyframes move { from { transform: translate(0%, 0%); } to { transform: translate(-100%, 100%); } } @keyframes dash { to { stroke-dashoffset: -227.62; } }
JavaScript
const colors = ["#0A4247", "#8C2F0D", "#F2A057", "#F2C185", "#8CB7B8"]; const shootingStarColors = ["#F2C185", "#8CB7B8"]; const ShootingStar = { template: '
', data() { return { shoot: false, x: 50, y: 50, arcOffset: 0, color: "" }; }, methods: { shootAStar() { if (Math.random() < 0.2) { this.x = Math.random() * 100; this.y = Math.random() * 100; this.arcOffset = Math.random() * 60 - 30; this.color = shootingStarColors[Math.floor(Math.random() * colors.length)]; this.shoot = true; setTimeout(() => { this.shoot = false; }, 600); } } }, mounted() { setInterval(this.shootAStar, 700); } }; const Star = { template: '
', data() { return { x: Math.floor(Math.random() * 100), y: Math.floor(Math.random() * 100), r: Math.random() * 2 + 0.5, color: colors[Math.floor(Math.random() * colors.length)] }; } }; const DynamicCircle = { template: '
', props: ["origin", "index"], data() { const mass = Math.random() * 0.8 + 0.4; return { sheet: new CSSStyleSheet(), animating: false, x: Math.floor(Math.random() * window.innerWidth), y: Math.floor(Math.random() * window.innerHeight), t: performance.now(), r: ((mass - 1.2) / (0.4 - 1.2)) * (14 - 2) + 2, vx: 0, vy: 0, // Spring stiffness, in kg / s^2 */ K: -(Math.random() * 30 + 10), // Damping constant, in kg / s B: -(Math.random() * 1.5 + 0.5), mass: mass, color: colors[Math.floor(Math.random() * colors.length)] }; }, watch: { origin: { handler() { if (!this.animating) { this.animating = true; this.t = performance.now(); requestAnimationFrame(this.tick); } }, deep: true } }, methods: { tick() { const now = performance.now(); const t = now - this.t; this.t = now; const spring_x = this.K * (this.x - this.origin.x); const damper_x = this.B * this.vx; this.ax = (spring_x + damper_x) / this.mass; this.vx += this.ax * (t / 1000); this.x += this.vx * (t / 1000); const spring_y = this.K * (this.y - this.origin.y); const damper_y = this.B * this.vy; this.ay = (spring_y + damper_y) / this.mass; this.vy += this.ay * (t / 1000); this.y += this.vy * (t / 1000); this.sheet.rules[0].style.transform = `translate(${this.x}px, ${this.y}px)`; requestAnimationFrame(this.tick); } }, created() { this.sheet.insertRule( `.circle-${this.index} { transform: translate(${this.x}px, ${this.y}px); }`, 0 ); document.adoptedStyleSheets = [...document.adoptedStyleSheets, this.sheet]; } }; new Vue({ el: "#app", components: { DynamicCircle, Star, ShootingStar }, data: { origin: {}, bounds: {}, circles: [] }, methods: { doThing(e) { Vue.set(this.origin, "x", e.x - this.bounds.x); Vue.set(this.origin, "y", e.y - this.bounds.y); }, doThingTouch(e) { Vue.set(this.origin, "x", e.touches[0].pageX - this.bounds.x); Vue.set(this.origin, "y", e.touches[0].pageY - this.bounds.y); } }, mounted() { this.bounds = this.$refs.svg.getBoundingClientRect(); } });
粒子
时间
文字
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号