本文へスキップ

TOP / MOTION LAB / ホバー

ホバー 読了目安 4分

吸着型・流体ボタン

概要

マウスに吸い寄せられて追従し、離すと水しぶきを飛ばしながらプルンと元に戻る、目を引くマグネティック(磁石)CTAボタン。

使用技術

実装ポイント

コアスニペット

const dist = Math.sqrt(dx * dx + dy * dy);
if (dist < triggerRadius) {
  gsap.to([this.bg, this.content], {
    x: dx * 0.5, y: dy * 0.5,
    rotationX: -dy * 0.1, rotationY: dx * 0.1,
    transformPerspective: 800,
    duration: 0.5, ease: "power2.out", overwrite: "auto",
  });
} else if (this.isHovering) {
  // リリース: elastic でプルンと原点復帰
  gsap.to([this.bg, this.content], {
    x: 0, y: 0, rotationX: 0, rotationY: 0,
    duration: 1.2, ease: "elastic.out(1, 0.3)", overwrite: true,
  });
}

// 毎フレームの自作パーティクル物理演算(放物線落下)
updateParticles() {
  for (let i = this.particles.length - 1; i >= 0; i--) {
    const p = this.particles[i];
    p.x += p.vx; p.y += p.vy;
    p.vy += p.gravity; // 重力を加算して放物線を描く
    p.life -= 0.02 + Math.random() * 0.02;
    if (p.life <= 0) { p.el.remove(); this.particles.splice(i, 1); }
    else gsap.set(p.el, { x: p.x, y: p.y, scale: p.life });
  }
}