根本鼠標的XY值,讓元素移動
<body> <img src="image/toux.ico" id="imgbug" alt="移動圖片"></body> <script type="text/javascript"> window.onload = function () { var ima = document.getElementById("imgbug"); ima.style.position = "absolute";//讓圖片絕對定位 //注冊鼠標的移動處理函數 document.onmousemove = function () { //改變圖片的坐標 //獲取鼠標的坐標 var x = event.clientX; var y = event.clientY; ima.style.left = x-ima.offsetWidth+"px"; ima.style.top = y - 76+"px"; } }</script>
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com