body { margin:0; padding:0; background:#111; } .pseudo-drag { width:120px; position:absolute; cursor:pointer; transition: transform 0.5s ease, top 0.5s ease, left 0.5s ease; border-radius:8px; } 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`; }); });