天天看點

一種帶氣泡格式的提示框

(一)、css/bubble-tooltip.css代碼如下:

#bubble_tooltip{

 width:147px;

 position:absolute;

 display:none;

}

#bubble_tooltip .bubble_top{

 background-image: url('../images/bubble_top.gif');

 background-repeat:no-repeat;

 height:16px; 

#bubble_tooltip .bubble_middle{

 background-image: url('../images/bubble_middle.gif');

 background-repeat:repeat-y; 

 background-position:bottom left;

 padding-left:7px;

 padding-right:7px;

#bubble_tooltip .bubble_middle span{

 position:relative;

 top:-8px;

 font-family: Trebuchet MS, Lucida Sans Unicode, Arial, sans-serif;

 font-size:11px;

#bubble_tooltip .bubble_bottom{

 background-image: url('../images/bubble_bottom.gif');

 background-repeat:no-repeat; 

 height:44px;

 top:-6px;

(二)、js/bubble-tooltip.js代碼如下:

function showToolTip(e,text){

 if(document.all)e = event;

 var obj = document.getElementById('bubble_tooltip');

 var obj2 = document.getElementById('bubble_tooltip_content');

 obj2.innerHTML = text;

 obj.style.display = 'block';

 var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);

 if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0;

 var leftPos = e.clientX - 100;

 if(leftPos<0)leftPos = 0;

 obj.style.left = leftPos + 'px';

 obj.style.top = e.clientY - obj.offsetHeight -1 + st + 'px';

function hideToolTip()

{

 document.getElementById('bubble_tooltip').style.display = 'none';

(三)、images/下面是氣泡的圖檔,可以到這裡免費下載下傳:

(四)、index.html頁面代碼如下:

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>JavaScript網頁氣泡提示框</title>

<style type="text/css">

 body{

  background-repeat:no-repeat;

  padding-top:85px; 

  font-family: Trebuchet MS, Lucida Sans Unicode, Arial, sans-serif;

  font-size:0.9em;

  line-height:130%;

 }

 a{

  color: #D60808;

  text-decoration:none;

 a:hover{

  border-bottom:1px dotted #317082;

  color: #307082;

 </style>

 <link rel="stylesheet" href="css/bubble-tooltip.css" media="screen">

 <script type="text/javascript" src="js/bubble-tooltip.js"></script>

</head>

<body>

<div id="bubble_tooltip">

 <div class="bubble_top"><span></span></div>

 <div class="bubble_middle"><span id="bubble_tooltip_content">Content is comming here as you probably can see.Content is comming here as you probably can see.</span></div>

 <div class="bubble_bottom"></div>

</div>

<h1>DHTML Balloon tooltip</h1>

<p>This demo demonstrates how the balloon tooltip works. Roll your mouse over the red links in the text below.</p>

<p><a href="#" onmouseover="showToolTip(event,'This is a simple, simple test');return false" onmouseout="hideToolTip()">Roll over me</a> to see the tooltip in action.</p>

<p>And here's some more content

<a href="#" onmouseover="showToolTip(event,'This is the content of the tooltihis is the content of the tooltiphis is the content of the tooltiphis is the content of the tooltiphis is the content of the tooltiphis is the content of the tooltiphis is the content of the tooltiphis is the content of the tooltiphis is the content of the tooltiphis is the content of the tooltiphis is the content of the tooltiphis is the content of the tooltiphis is the content of the tooltipp. This is the content of the tooltip.');return false" onmouseout="hideToolTip()">sharejs.com</a> </p>

<p>This is the last piece of the content on this web page</p>

<br><br>

</body>

</html>

繼續閱讀