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

首頁 > 編程 > JavaScript > 正文

輕量級 JS ToolTip提示效果

2019-11-21 00:20:43
字體:
來源:轉載
供稿:網友
鼠標經過出現的提示效果,比title更漂亮,可訂制。
JS:
復制代碼 代碼如下:

//---------------------------tooltip效果 start-----------------------------------
//獲取某個html元素的定位
function GetPos(obj){
var pos=new Object();
pos.x=obj.offsetLeft;
pos.y=obj.offsetTop;
while(obj=obj.offsetParent){
pos.x+=obj.offsetLeft;
pos.y+=obj.offsetTop;
}
return pos;
};

//提示工具
var ToolTip={
_tipPanel:null,
Init:function(){
if(null==this._tipPanel){
var tempDiv=document.createElement("div");
document.body.insertBefore(tempDiv, document.body.childNodes[0]);
tempDiv.id="tipPanel";
tempDiv.style.display="none";
tempDiv.style.position="absolute";
tempDiv.style.zIndex="999";
}
},
AttachTip:function(){}, //添加提示綁定
DetachTip:function(){}, //移除提示綁定
ShowTip:function(oTarget){
if($("tipPanel")==null)
return;

/*操作流程
*1、構建新的html片段
*2、設置提示框新位置
*3、顯示提示框
*/
//1.
var tempStr=""; //html片段
if(arguments.length>1){
for(var i=1;i<arguments.length;i++){
tempStr+="<p>"+arguments[i]+"</p>";
}
}
$("tipPanel").innerHTML=tempStr;
//2.
var pos=GetPos(oTarget);
$("tipPanel").style.left=(oTarget.offsetWidth/2+pos.x)+"px";
$("tipPanel").style.top=(oTarget.offsetHeight+pos.y)+"px";
//3.
$("tipPanel").style.display="";
},
HideTip:function(){
if($("tipPanel")==null)
return;
$("tipPanel").style.display="none";
}
};

//---------------------------tooltip效果 end-----------------------------------

CSS:
復制代碼 代碼如下:

#tipPanel{ background:white; padding:6px 8px; width:300px; border:solid 4px #09c; font-size:14px; color:#555;}
#tipPanel p{ margin:0px;}
#tipPanel b{ color:red; font-size:14px;}


HTML調用:
復制代碼 代碼如下:

<body>
<input type="button" value="hover me" onmouseover='ToolTip.ShowTip(this,"<b>日期:</b>2010-7-19");' onmouseout='ToolTip.HideTip();' style="margin:200px 100px;" />
</body>
<script type="text/javascript">
//initialize tooltip control
ToolTip.Init();
</script>


使用效果:

上面的$("id")作用等價于document.getElementById("id")
AttachTip:function(){}, //添加提示綁定
DetachTip:function(){}, //移除提示綁定
這兩行,可以用動態綁定事件完成,因為項目里面用不著,所以暫時沒加
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 巴楚县| 商河县| 合川市| 富川| 达拉特旗| 台安县| 遂昌县| 丹巴县| 高密市| 通河县| 颍上县| 秭归县| 商丘市| 十堰市| 阿城市| 镶黄旗| 息烽县| 嘉荫县| 施秉县| 邢台县| 灵川县| 手游| 蒙城县| 沧州市| 布尔津县| 长汀县| 左云县| 镇赉县| 溧水县| 延寿县| 同德县| 措美县| 甘孜县| 兴城市| 聂荣县| 柳河县| 开远市| 剑川县| 疏附县| 通江县| 洛浦县|