<!--TCD049--><script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.9.1/gsap.min.js"></script>
<script>
var isDesktop = window.innerWidth > 960;
if (isDesktop) {
(function() {
var TiCodeMag = document.querySelectorAll('.ti-magnet');
var TiCodeRotate = true;
TiCodeMag.forEach(function(elem) {
document.addEventListener('mousemove', function(e) {
TiMagnetize(elem, e);
});
});
function TiMagnetize(el, e) {
var mX = e.pageX,
mY = e.pageY;
const item = $(el);
const customDist = 200;
const centerX = item.offset().left + (item.width() / 2);
const centerY = item.offset().top + (item.height() / 2);
var deltaX = Math.floor((centerX - mX)) * -1;
var deltaY = Math.floor((centerY - mY)) * -1;
var distance = TiCalculateDistance(centerX, centerY, mX, mY);
var rotation = 0;
if (TiCodeRotate) {
if (mX < centerX) {
rotation = 25;
} else {
rotation = -25;
}
} else {
rotation = 25;
}
if (distance < customDist) {
gsap.to(item, 1, { y: deltaY, x: deltaX, scale: 1, rotation: rotation });
item.addClass('magnet');
} else {
gsap.to(item, 0.6, { y: 0, x: 0, scale: 1, rotation: 0 });
item.removeClass('magnet');
}
}
function TiCalculateDistance(centerX, centerY, mouseX, mouseY) {
return Math.floor(Math.sqrt(Math.pow(mouseX - centerX, 2) + Math.pow(mouseY - centerY, 2)));
}
function TiLerp(a, b, n) {
return (1 - n) * a + n * b;
}
class TiCursor {
constructor() {
this.bind();
this.cursor = document.querySelector('.js-cursor');
this.mouseCurrent = {
x: 0,
y: 0
};
this.mouseLast = {
x: this.mouseCurrent.x,
y: this.mouseCurrent.y
};
this.rAF = undefined;
}
bind() {
['getMousePosition', 'run'].forEach((fn) => this[fn] = this[fn].bind(this));
}
getMousePosition(e) {
this.mouseCurrent = {
x: e.clientX,
y: e.clientY
};
}
run() {
this.mouseLast.x = TiLerp(this.mouseLast.x, this.mouseCurrent.x, 0.2);
this.mouseLast.y = TiLerp(this.mouseLast.y, this.mouseCurrent.y, 0.2);
this.mouseLast.x = Math.floor(this.mouseLast.x * 100) / 100;
this.mouseLast.y = Math.floor(this.mouseLast.y * 100) / 100;
this.cursor.style.transform = `translate3d(${this.mouseLast.x}px, ${this.mouseLast.y}px, 0)`;
this.rAF = requestAnimationFrame(this.run);
}
requestAnimationFrame() {
this.rAF = requestAnimationFrame(this.run);
}
addEvents() {
window.addEventListener('mousemove', this.getMousePosition, false);
}
on() {
this.addEvents();
this.requestAnimationFrame();
}
init() {
this.on();
}
}
const tiCursor = new TiCursor();
tiCursor.init();
})();
}
</script>