const imgs = document.querySelectorAll(‘.pseudo-drag’);
imgs.forEach(img => {
img.addEventListener(‘mouseenter’, () => {
// ランダム移動距離
const dx = (Math.random() – 0.5) * 100; // -50px ~ +50px
const dy = (Math.random() – 0.5) * 100;
// 現在位置を取得
const top = parseFloat(img.style.top);
const left = parseFloat(img.style.left);
// 新しい位置に移動(画面外にはみ出さないように制限)
img.style.top = `${Math.max(0, top + dy)}px`;
img.style.left = `${Math.max(0, left + dx)}px`;
});
});
