jquery實現的獲取滑鼠位置並彈出提示框
阿新 • • 發佈:2019-02-10
在做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>
效果圖片如下: