国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

javascript 實用的文字鏈提示框效果

2019-11-21 00:24:00
字體:
來源:轉載
供稿:網友
效果要基本實現以下功能:
(1)鼠標滑過文章中的鏈接文字,要在相應位置彈出提示框,提示框的樣式由css來控制,高度自適應;鼠標可以點擊提示框的中的鏈接,滑離提示框時,框自動消失;
(2)把提示框的位置控制在文本域范圍之內,如果鏈接文字處在文本域左側,提示框要居右顯示,使其不會出離文本域;反之,如果鏈接文字處在文本域右側,提示框要居左顯示;
(3)如果文本域內容很多,而鏈接文字恰巧處于瀏覽器底部,為了使提示框不出離于瀏覽器的可視范圍,提示框的位置要自動調整到鏈接文字的上面;

1.css
復制代碼 代碼如下:

.main{width:950px; border:#9C3 1px solid; margin:0 auto; padding:15px; background-color:#fff; line-height:25px;font-size:14px; position:relative;}
span{border:#70bce4 2px solid; display:block; position:absolute; background-color:#FFF; padding:5px 10px; font-size:12px; width:200px; display:none;}
.cur{color:#900;}

2.js
復制代碼 代碼如下:

//獲取對象元素的函數;
function $a(id,tag){var re=(id&&typeof id!="string")?id:document.getElementById(id);if(!tag){return re;}else{return re.getElementsByTagName(tag);}}
function tips(){
//獲取文本域中的a元素列表;
var article=$a("article","a")
for(i=0;i<article.length;i++){
//遍歷a元素,不包含類"cur"的a元素將不會執行之后的代碼;
if(article[i].className.indexOf("cur")==-1) continue;
article[i].onmouseover=function(e){
//獲取鼠標指針在瀏覽器可視區域的坐標,不受文檔內容影響;
var e=e||event;
posX = e.clientX;
posY = e.clientY;
//獲取瀏覽器可視區域高度;
var bodyhe=document.documentElement.clientHeight;
var parwidth=$a("article").offsetWidth;
var tipbox=get_nextSibling(this);
var boxlist=$a("article","span")
//設置文本區域中的span提示框均為隱藏狀態;
for(j=0;j<boxlist.length;j++){
boxlist[j].style.display="none";
boxlist[j].innerHTML="調入后臺數據"
}
//設置當前的提示框顯示;
tipbox.style.display="block";
var w=tipbox.offsetWidth-this.offsetWidth;
/*
以id為article的div添加了相對定位position:relative,所以它已經是提示框的父級;
控制彈出框的顯示位置;
*/
tipbox.style.left=(this.offsetLeft>parwidth/2?this.offsetLeft-w:this.offsetLeft)+"px";
tipbox.style.top=(posY+tipbox.offsetHeight>bodyhe?this.offsetTop-tipbox.offsetHeight:document.all?this.offsetTop+15:this.offsetTop+this.offsetHeight)+"px";
tipbox.onmouseover=function(){this.style.display="block";}
tipbox.onmouseout=this.onmouseout=function(){tipbox.style.display="none";}
}
}
}
//獲取對象元素的下一個標簽節點;
function get_nextSibling(n){
var x=n.nextSibling;
while (x.nodeType!=1){
x=x.nextSibling;
}
return x;
}

貼出源文件代碼 感興趣的朋友可以測試一下,有問題可留言 @&@
復制代碼 代碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>提示框效果</title>
<style type="text/css">
.main{width:950px; border:#9C3 1px solid; margin:0 auto; padding:15px; background-color:#fff; line-height:25px;font-size:14px; position:relative;}
span{border:#70bce4 2px solid; display:block; position:absolute; background-color:#FFF; padding:5px 10px; font-size:12px; width:200px; display:none;}
.cur{color:#900;}
</style>
</head>
<body onload="tips();">
<br />
<br />
<br />
<br />
<div class="main" id="article">
早在陳冠希“艷照門”事件爆發之前,陳冠希老爸就曾被傳包養內地男星胡兵。所謂無風不起浪,兩人曾被媒體拍到一起吃飯逛街的鏡頭。而<a href="#" class="cur">胡兵</a><span><a href="#">雙響炮上海開機</a><br /><a href="#">雙響炮上海開機</a><br /><a href="#">雙響炮上海開機</a></span>本人的曖昧態度也為此事件更增添了一份迷霧。早在陳冠希“艷照門”事件爆發之前,陳冠希老爸就曾被傳包養內地男星胡兵。所謂無風不起浪,兩人曾被媒體拍到一起吃飯逛街的鏡頭。而<a href="#" class="cur">胡兵</a><span><a href="#">雙響炮上海開機</a><br /><a href="#">雙響炮上海開機</a><br /><a href="#">雙響炮上海開機</a></span>本人的曖昧態度也為此事件更增添了一份迷霧。 早在陳冠希“艷照門”事件爆發之前,陳冠希老爸就曾被傳包養內地男星胡兵。所謂無風不起浪,兩人曾被媒體拍到一起吃飯逛街的鏡頭。而<a href="#" class="cur">胡兵</a><span><a href="#">雙響炮上海開機</a><br /><a href="#">雙響炮上海開機</a><br /><a href="#">雙響炮上海開機</a></span>本人的曖昧態度也為此事件更增添了一份迷霧。
</div>
<script type="text/javascript">
function $a(id,tag){var re=(id&&typeof id!="string")?id:document.getElementById(id);if(!tag){return re;}else{return re.getElementsByTagName(tag);}}
function tips(){
var article=$a("article","a")
for(i=0;i<article.length;i++){
if(article[i].className.indexOf("cur")==-1) continue;
article[i].onmouseover=function(e){
var e=e||event;
posX = e.clientX;
posY = e.clientY;
var bodyhe=document.documentElement.clientHeight;
var parwidth=$a("article").offsetWidth;
var tipbox=get_nextSibling(this);
var boxlist=$a("article","span")
for(j=0;j<boxlist.length;j++){
boxlist[j].style.display="none";
boxlist[j].innerHTML="調入后臺數據"
}
tipbox.style.display="block";
var w=tipbox.offsetWidth-this.offsetWidth;
tipbox.style.left=(this.offsetLeft>parwidth/2?this.offsetLeft-w:this.offsetLeft)+"px";
tipbox.style.top=(posY+tipbox.offsetHeight>bodyhe?this.offsetTop-tipbox.offsetHeight:document.all?this.offsetTop+15:this.offsetTop+this.offsetHeight)+"px";
tipbox.onmouseover=function(){this.style.display="block";}
tipbox.onmouseout=this.onmouseout=function(){tipbox.style.display="none";}
}
}
}
function get_nextSibling(n){
var x=n.nextSibling;
while (x.nodeType!=1){
x=x.nextSibling;
}
return x;
}
</script>
</body>
</html>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 云梦县| 峨眉山市| 绿春县| 郓城县| 阿拉尔市| 逊克县| 开封市| 临澧县| 镇康县| 连城县| 盘锦市| 阿城市| 海门市| 新兴县| 黄梅县| 田东县| 句容市| 南丹县| 恩平市| 巴彦县| 德阳市| 启东市| 兰州市| 巴楚县| 甘南县| 广汉市| 鲁甸县| 江源县| 延寿县| 辽宁省| 乌拉特中旗| 江永县| 彰武县| 迁安市| 当雄县| 宜昌市| 贡山| 牙克石市| 澄迈县| 玉门市| 新巴尔虎左旗|