perf: optimize images and throttle/disable magic cursor on mobile

This commit is contained in:
mstfyldz
2026-05-05 00:10:04 +03:00
parent 5808186afc
commit 7ea420daba
2 changed files with 27 additions and 19 deletions

View File

@@ -27,6 +27,8 @@ class Cursor {
}).on('mouseenter', () => {
self.show();
}).on('mousemove', (e) => {
if (this.lastMove && Date.now() - this.lastMove < 16) return; // Throttle to ~60fps
this.lastMove = Date.now();
this.pos = {
x: this.stick ? this.stick.x - ((this.stick.x - e.clientX) * 0.15) : e.clientX,
y: this.stick ? this.stick.y - ((this.stick.y - e.clientY) * 0.15) : e.clientY
@@ -95,33 +97,39 @@ class Cursor {
}
update() {
if (!this.visible) return;
this.move();
this.show();
}
move(x, y, duration) {
if (!this.el.length) return;
gsap.to(this.el, {
x: x || this.pos.x,
y: y || this.pos.y,
force3D: true,
overwrite: true,
overwrite: "auto",
ease: this.options.ease,
duration: this.visible ? (duration || this.options.speed) : 0
});
}
show() {
if (this.visible) return;
clearInterval(this.visibleInt);
if (this.visible || !this.el.length) return;
this.el.addClass('-visible');
this.visibleInt = setTimeout(() => this.visible = true);
this.visible = true;
}
hide() {
clearInterval(this.visibleInt);
if (!this.el.length) return;
this.el.removeClass('-visible');
this.visibleInt = setTimeout(() => this.visible = false, this.options.visibleTimeout);
this.visible = false;
}
}
// Init cursor
const cursor = new Cursor();
// Init cursor only on desktop and after load
$(window).on('load', function() {
if (window.innerWidth > 1024 && !('ontouchstart' in window)) {
const cursor = new Cursor();
}
});