您的位置:首页 > Web前端 > JQuery

jquery实现的获取鼠标位置并弹出提示框

2012-11-19 15:54 639 查看
在做Web应用的时候,有时候为了增强用户体验,当用户鼠标放在某个图片或者按钮上时,需要给一些互动性的提示。当然,HTML中已经自带了这项功能,就是alt=“”,但有时觉得这个看起来不够美观,所以就自己用css写了个弹出框,并用jquery实现了效果,代码如下:

<!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=gbk" />
<script type="text/javascript" src="jquery.js"></script>
<title>HTML+CSS圆角提示框</title>
<style type="text/css">
/*提示圆角框*/
.circle_bot { width:80px; clear:both; font: 15px/1.125 Arial; display:none;z-index: 9999;position: absolute;}
.circle_bot .s_b b, .circle_bot span.s_i i { font-size:1px; line-height:1px; overflow:hidden; display:block; clear:both;z-index: 9999;}
.circle_bot .s_b b, .circle_bot span.s_i i, .circle_bot .info { background:#FAFFF0; border:#000 solid; z-index: 9999;}
.circle_bot b.b1 { border-width:1px 0 0 0; margin:0 2px; height:0px; z-index: 9999;}
.circle_bot b.b2 { border-width:0 1px; margin:0 1px; height:1px; z-index: 9999;}
.circle_bot span.s_i i { height:1px; border-width:0 1px; z-index: 9999;}
.circle_bot .i1 { width:0px; margin-left:36px; z-index: 9999;}
.circle_bot .i2 { width:2px; margin-left:35px; z-index: 9999;}
.circle_bot .i3 { width:4px; margin-left:34px; z-index: 9999;}
.circle_bot .i4 { width:6px; margin-left:33px; z-index: 9999;}
.circle_bot .i5 { width:8px; margin-left:32px; z-index: 9999;}
.circle_bot .i6 { width:10px; margin-left:31px; margin-top:-1px;z-index: 9999;}
.circle_bot .info { border-width:0 1px; color:#333; padding:5px;z-index: 9999;}
</style>
<script text="text/javascript">
$(function(){
var tip = $(".circle_bot");
$("#button").mouseover(function(e){
tip.css("margin-left",e.pageX-50+"px").css("margin-top",e.pageY-50+"px");
tip.css("display","block");
})
$("#button").mouseout(function(){
tip.css("display","none");
})
})
</script>
</head>
<body>
<div class="circle_bot">
<span class="s_b"> <b class="b1"></b> <b class="b2"></b></span>
<div class="info">提示提示</div>
<span class="s_b"><b class="b2"></b> <b class="b1"></b></span>
<span class="s_i"> <i class="i6"></i> <i class="i5"></i> <i class="i4"></i> <i class="i3"></i> <i class="i2"></i> <i class="i1"></i></span>
</div>
<div><img style="margin-left:100px; margin-top:100px;" src="logo.png" id="button"></div>
</body>
</html>

效果图片如下:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: