css + javascript 制作tips

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Html</title>
<style type="text/css">
.tooltip {
position: relative;
display: inline-block;
cursor: help;
white-space: nowrap;
border-bottom: 1px dotted #777;
padding-top:100px;

}

.tooltip-content {
opacity: 0;
visibility: hidden;
font: 12px Arial, Helvetica;
text-align: center;
border-color: #aaa #555 #555 #aaa;
border-style: solid;
border-width: 1px;
width: 150px;
padding: 15px;
position: absolute;
bottom: 40px;
left: 50%;
margin-left: -76px;

background-color: #fff;
background-image: -webkit-gradient(linear, left top, left bottom, from(rgba(0,0,0,.1)), to(rgba(255,255,255,0)));
background-image: -webkit-linear-gradient(rgba(0,0,0,.1), rgba(255,255,255,0));
background-image: -moz-linear-gradient(rgba(0,0,0,.1), rgba(255,255,255,0));
background-image: -ms-linear-gradient(rgba(0,0,0,.1), rgba(255,255,255,0));
background-image: -o-linear-gradient(rgba(0,0,0,.1), rgba(255,255,255,0));
background-image: linear-gradient(rgba(0,0,0,.1), rgba(255,255,255,0));
-moz-box-shadow: 1px 1px 0 #555,
2px 2px 0 #555,
3px 3px 1px rgba(0, 0, 0, .3),
0   1px 0   rgba(255,255,255, .5) inset;
-webkit-box-shadow: 1px 1px 0 #555,
2px 2px 0 #555,
3px 3px 1px rgba(0, 0, 0, .3),
0   1px 0   rgba(255,255,255, .5) inset;
box-shadow: 1px 1px 0 #555,
2px 2px 0 #555,
3px 3px 1px rgba(0, 0, 0, .3),
0   1px 0   rgba(255,255,255, .5) inset;
-webkit-transition: bottom .2s ease, opacity .2s ease;
-moz-transition: bottom .2s ease, opacity .2s ease;
-ms-transition: bottom .2s ease, opacity .2s ease;
-o-transition: bottom .2s ease, opacity .2s ease;
transition: bottom .2s ease, opacity .2s ease;
}

.tooltip-content:after,
.tooltip-content:before {
border-right: 16px solid transparent;
border-top: 15px solid #fff;
bottom: -15px;
content: "";
position: absolute;
left: 50%;
margin-left: -10px;
}

.tooltip-content:before {
border-right-width: 25px;
border-top-color: #555;
border-top-width: 15px;
bottom: -15px;
}

.tooltip:hover .tooltip-content{
opacity: 1;
visibility: visible;
bottom: 30px;
}
</style>
<script type="text/javascript">
jquery(document).ready(function(){
$('[data-tooltip]').addClass('tooltip');
$('.tooltip').each(function() {
$(this).append('' + $(this).attr('data-tooltip') + '');
});

if ($.browser.msie && $.browser.version.substr(0,1)<7)
{
  $('.tooltip').mouseover(function(){
$(this).children('.tooltip-content').css('visibility','visible');
  }).mouseout(function(){
$(this).children('.tooltip-content').css('visibility','hidden');
  })
}
});
</script>
</head>
<body>
<!-- <div class="tooltip">这是我的文字<span>这是我的说明描述文字。</span></div> -->
<div class="tooltip" data-tooltip="Action Role-Playing">
这是我的文字
<span class="tooltip-content">这是我的说明描述文字。</span>
</div>

<script language="javascript">
function show(tips,flag,url){
var my_tips=document.all.mytips;
if(flag){
  my_tips.style.display="";
  if (url!=null){
   my_tips.innerHTML="<img src='"+url+"'align=left>"+tips;
  }
  else{
   my_tips.innerHTML=tips;
  }
     my_tips.style.left=event.clientX+10+document.body.scrollLeft;
  my_tips.style.top=event.clientY+10+document.body.scrollTop;
      }
else
{
  my_tips.style.display="none";
}
}
</script>
<div id="mytips" name="mytips" style="position:absolute;width:150;height:16;border:1 gray solid;font-size:9pt;background-color:#ffffff;color:red;display:none;filter: progid:DXImageTransform.Microsoft.Shadow(color=#999999,direction=135,strength=3);"></div>
<td><font color="#FF0000"  tips="截止日期:2007-08-21" onmousemove="show(this.tips,1);" onmouseout="show(this.tips,0)">已售出</font></td>
</body>
</html>

猜你喜欢

转载自tomhat.iteye.com/blog/2076770