您好,登錄后才能下訂單哦!
本文實(shí)例為大家分享了js實(shí)現(xiàn)圓形顯示鼠標(biāo)單擊位置的具體代碼,供大家參考,具體內(nèi)容如下
代碼如下:
<!DOCTYPE html> <head> <meta charset="UTF-8"> <title>顯示鼠標(biāo)單擊位置</title> <style> .mouse{position:fixed;background:#ffd965;width:40px;height:40px;border-radius:20px;display:none;} </style> <script> window.onload = function(){ var mouse = document.getElementById('mouse'); //需求:鼠標(biāo)在頁(yè)面上單擊時(shí),獲取單擊時(shí)的位置,并顯示一個(gè)小圓點(diǎn) document.onclick = function() { mouse.style.display = 'block'; // 獲取事件對(duì)象的兼容處理 var targetX = event.clientX - mouse.offsetWidth / 2; var targetY = event.clientY - mouse.offsetHeight / 2; // 在鼠標(biāo)單擊的位置顯示<div> mouse.style.left = targetX + 'px'; mouse.style.top = targetY + 'px'; }; } </script> </head> <body> <div id="mouse" class="mouse"></div> </body> </html>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。