javaScript實現(xiàn)鼠標(biāo)在文字上懸浮時彈出懸浮層效果
在人人,CSDN等一些網(wǎng)站,當(dāng)鼠標(biāo)在某個東西上懸浮時,會彈出一個懸浮層,鼠標(biāo)移開懸浮層消失。
比如說CSDN的通知(應(yīng)該是進(jìn)入寫新文章的頁面后頁面上方的那個鈴鐺),具體是什么實現(xiàn)的呢?上代碼:
<!doctype html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TEST</title>
</head>
<style type="text/css">
body{
position: relative;
}
#inform{
position: absolute;
top: 20px;
width: 350px;
max-height: 250px; /* 設(shè)置最大高度,當(dāng)高度達(dá)到此值時出現(xiàn)滾動條 */
z-index: 10;
background-color: #E0E5E5;
overflow: auto; /* 自動添加滾動條 */
box-shadow:0px 0px 10px #000; /* 外陰影 */
display: none; /* 默認(rèn)隱藏 */
}
#informTable{
table-layout:fixed; /* 用于實現(xiàn)表格td自動換行的部分代碼*/
width: 325px;
}
#informTable tr td{
width: 325px;
height:30px;
font-size: 16px;
font-family: Georgia;
color: #555555;
word-wrap:break-word; /*自動換行*/
padding: 0 0 0 0;
}
#informTable tr td:hover{
background-color: #D9D9D9;
}
#inform hr{
border:1;
width: 325px;
margin-bottom: 0px;
}
</style>
<script type="text/javascript">
//顯示懸浮層
function showInform(){
document.getElementById("inform").style.display='block';
// document.getElementById("inform").css("display","block");
}
//隱藏懸浮層
function hiddenInform(event){
var informDiv = document.getElementById('inform');
var x=event.clientX;
var y=event.clientY;
var divx1 = informDiv.offsetLeft;
var divy1 = informDiv.offsetTop;
var divx2 = informDiv.offsetLeft + informDiv.offsetWidth;
var divy2 = informDiv.offsetTop + informDiv.offsetHeight;
if( x < divx1 || x > divx2 || y < divy1 || y > divy2){
document.getElementById('inform').style.display='none';
}
}
</script>
<body>
<a id="btn" onMouseOver="javascript:showInform();" onMouseOut="hiddenInform()">
警告消息
</a>
<div id="inform" onMouseOver="javascript:showInform();" onMouseOut="hiddenInform(event)">
<table id="informTable">
<tr>
<td>
編號5005車輛發(fā)車間隔異常
<hr/>
</td>
</tr>
<tr>
<td>
編號5005車輛發(fā)車間隔異常
<hr/>
</td>
</tr>
<tr>
<td>
編號5005車輛發(fā)車間隔異常
<hr/>
</td>
</tr>
<tr>
<td>
編號5005車輛發(fā)車間隔異常
<hr/>
</td>
</tr>
<tr>
<td>
編號5005車輛發(fā)車間隔異常
<hr/>
</td>
</tr>
<tr>
<td>
編號5005車輛發(fā)車間隔異常
<hr/>
</td>
</tr>
<tr>
<td>
編號5005車輛發(fā)車間隔異常
<hr/>
</td>
</tr>
<tr>
<td>
編號5005車輛發(fā)車間隔異常
<hr/>
</td>
</tr>
</table>
</div>
</body>
</html>
效果圖如下:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
深入理解關(guān)于javascript中apply()和call()方法的區(qū)別
下面小編就為大家?guī)硪黄钊肜斫怅P(guān)于javascript中apply()和call()方法的區(qū)別。小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-04-04
詳解小程序中h5頁面onShow實現(xiàn)及跨頁面通信方案
這篇文章主要介紹了小程序中h5頁面onShow實現(xiàn)及跨頁面通信方案,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-05-05
layui form.render(''select'', ''test2'') 更新渲染的方法
今天小編就為大家分享一篇layui form.render('select', 'test2') 更新渲染的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-09-09
javascript實現(xiàn)編寫網(wǎng)頁版計算器
這篇文章主要為大家詳細(xì)介紹了javascript實現(xiàn)編寫網(wǎng)頁版計算器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-08-08
js實現(xiàn)仿Windows風(fēng)格選項卡和按鈕效果實例
這篇文章主要介紹了js實現(xiàn)仿Windows風(fēng)格選項卡和按鈕效果的方法,可實現(xiàn)類似windows選項卡風(fēng)格的tab標(biāo)簽效果,需要的朋友可以參考下2015-05-05

