基于JavaScript實現(xiàn)鼠標(biāo)懸浮彈出跟隨鼠標(biāo)移動的帶箭頭的信息層
更新時間:2016年01月18日 09:06:39 投稿:mrr
這篇文章主要介紹了基于JavaScript實現(xiàn)鼠標(biāo)懸浮彈出跟隨鼠標(biāo)移動的帶箭頭的信息層 的相關(guān)資料,需要的朋友可以參考下
很多網(wǎng)站,當(dāng)鼠標(biāo)懸浮在一個元素上的時候能夠彈出一個信息說明層,并且此層能夠跟隨鼠標(biāo)移動,同時彈出的層帶有箭頭,此箭頭指向鼠標(biāo)懸浮的元素,下面就通過實例代碼簡單介紹一下如何實現(xiàn)此效果。
代碼實例如下:
<!DOCTYPE html>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="http://www.dhdzp.com/" />
<title>腳本之家</title>
<style type="text/css">
#content
{
width:100px;
height:100px;
background:green;
position:relative;
margin:100px;
}
#inform
{
width:200px;
height:200px;
border:1px solid #ccc;
background:white;
display:none;
position:absolute;
}
#inform span
{
width:0px;
height:0px;
border-width:10px;
border-style:none solid solid none;
position:absolute;
}
#inform .tb-border
{
left:-10px;
border-color:transparent #ccc transparent transparent;
top:-1px;
}
#inform .tb-background
{
left:-9px;
border-color:transparent white transparent transparent;
}
</style>
<script type="text/javascript">
window.onload=function()
{
var content=document.getElementById("content");
var inform=document.getElementById("inform");
content.onmouseover=function(ev)
{
var ev=ev||event;
inform.style.display="block";
inform.style.left=(ev.clientX-this.offsetLeft+20)+"px";
inform.style.top=(ev.clientY-this.offsetTop-20)+"px";
}
content.onmousemove=function(ev)
{
var ev=ev||event;
inform.style.left=(ev.clientX-this.offsetLeft+20)+"px";
inform.style.top=(ev.clientY-this.offsetTop-10)+"px";
}
content.onmouseout=function(ev){inform.style.display="none";}
}
</script>
</head>
<body>
<div id="content">
<div id="inform">
<span class="tb-border"></span>
<span class="tb-background"></span>
</div>
</div>
</body>
</html>
以上代碼實現(xiàn)了我們的要求,當(dāng)鼠標(biāo)放在div中的時候能夠彈出一個信息層,并且能夠跟隨鼠標(biāo)移動,彈出層的帶有指示的箭頭,代碼非常的簡單這里就不多介紹了,如有任何疑問可以跟帖留言或者參閱相關(guān)閱讀。
相關(guān)文章
JavaScript簡單獲取系統(tǒng)當(dāng)前時間完整示例
這篇文章主要介紹了JavaScript簡單獲取系統(tǒng)當(dāng)前時間的方法,涉及javascript針對日期與時間的判斷以及字符串組合的相關(guān)技巧,需要的朋友可以參考下2016-08-08
根據(jù)表格中的某一列進(jìn)行排序的javascript代碼
根據(jù)表格中的某一列進(jìn)行排序的實現(xiàn)方法有很多,下面為大家介紹下如何使用js來簡單實現(xiàn)下,需要的朋友不要錯過2013-11-11

