gsap(一) 跟着鼠标移动的小球
gsap.quickTo()
<div style="width: 500px;height: 400px;background-color: lavender;margin-left:40px;margin-top:30px;" #parent>
<div style="width: 30px;height: 30px;border-radius: 50%;background-color: lightpink;" #child></div>
</div>
const parent = this.parent.nativeElement;
const child = this.child.nativeElement;
let xTo = gsap.quickTo(child, 'x', {duration: .4, ease: 'power3'});
let yTo = gsap.quickTo(child, 'y', {duration: .4, ease: 'power3'});
// 从固定值到x 200的动画
// xTo(200)
// 从500->100 的动画
// xTo(100, 500)
const offsetX: number = parent.getBoundingClientRect().x
const offsetY: number = parent.getBoundingClientRect().y
const width: number = parent.getBoundingClientRect().width;
const height: number = parent.getBoundingClientRect().height;
const childWidth: number = child.getBoundingClientRect().width;
const childHeight: number = child.getBoundingClientRect().height;
parent.addEventListener('mousemove', (e: MouseEvent) => {
let x = e.pageX - offsetX - childWidth / 2;
let y = e.pageY - offsetY - childHeight / 2;
let leftBound = width - childWidth;
let bottomBound = height - childHeight;
console.log(childWidth, bottomBound);
if (x <= 0) {
x = 0;
} else if (x > leftBound) {
x = leftBound
}
if (y <= 0) {
y = 0;
} else if (y > bottomBound) {
y = bottomBound
}
xTo(x);
yTo(y)
})
gsap.quickSetter()
只需要把对应的改改
let xTo = gsap.quickTo(child, 'x', {duration: .4, ease: 'power3'});
let yTo = gsap.quickTo(child, 'y', {duration: .4, ease: 'power3'});
xSet(x)
ySet(y)
设置随机位置
var boxSet = gsap.quickSetter("#box", "css");
boxSet({x:"+=100", y:"random(-100, 100)"});
设置圆的位置
var circleSet = gsap 。quickSetter ( "#circle" , "attr" );
circleSet ({ cx : "+=100" , cy : "random(-100, 100)" });
决定自己的高度的是你的态度,而不是你的才能
记得我们是终身初学者和学习者
总有一天我也能成为大佬

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
2019-05-04 python(二)面向对象知识点