欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js實(shí)現(xiàn)圓形顯示鼠標(biāo)單擊位置

 更新時(shí)間:2020年02月11日 10:28:25   作者:da_yu_hai_tang  
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)圓形顯示鼠標(biāo)單擊位置,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(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í)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論