js實現(xiàn)圓形顯示鼠標(biāo)單擊位置
更新時間:2020年02月11日 10:28:25 作者:da_yu_hai_tang
這篇文章主要為大家詳細(xì)介紹了js實現(xiàn)圓形顯示鼠標(biāo)單擊位置,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了js實現(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)在頁面上單擊時,獲取單擊時的位置,并顯示一個小圓點
document.onclick = function() {
mouse.style.display = 'block';
// 獲取事件對象的兼容處理
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>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
微信小程序自定義tabbar custom-tab-bar 6s出不來解決方案(cover-view不兼容)
這篇文章主要介紹了微信小程序自定義tabbar custom-tab-bar 6s出不來解決方案,cover-view不兼容問題,需要的朋友可以參考下2019-11-11

