jquery实现⿏标滑过显⽰提⽰框的⽅法本⽂实例讲述了jquery实现⿏标滑过显⽰提⽰框的⽅法。分享给⼤家供⼤家参考。具体如下:
⼀、jquery⿏标滑过显⽰提⽰框实例
1、效果图
2、实现代码 ( 需要⾃⾏添加 jquery.js、按钮图⽚、提⽰框图⽚ )
HTML 代码
复制代码代码如下:
<!DOCTYPE>
<html>
<head>
weight的几种形式<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Animated Menu Hover 1</title>
<script type="text/javascript" src="jquery。js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".menu li").hover(function() {
$(this).find("em").animate({opacity: "show", top: "-75"}, "slow");
}, function() {
$(this).find("em").animate({opacity: "hide", top: "-85"}, "fast");
});
});
</script>
<style type="text/css">
body {
margin: 10px auto;
width: 570px;
font: 75%/120% Arial, Helvetica, sans-serif;
}
.menu {
margin: 100px 0 0;
padding: 0;
list-style: none;
}
.menu li {
padding: 0;
margin: 0 2px;
float: left;
position: relative;
text-align: center;
}
.menu a {
padding: 14px 10px;
display: block;
color: #000000;
width: 144px;
text-decoration: none;
font-weight: bold;
background: url('背景图⽚1') no-repeat center center;
}
.menu li em {
background: url('背景图⽚2') no-repeat;
width: 180px;
height: 45px;
position: absolute;
top: -85px;
left: -15px;
text-align: center;
padding: 20px 12px 10px;
font-style: normal;
z-index: 2;
display: none;
}
</style>
</head>
<body>
<ul class="menu">
<li>
<a href="www.jb51">Web Designer Wall</a>
<em>A wall of design ideas, web trends, and tutorials</em>
</li>
<li>
<a href="www.jb51">Best Web Gallery</a>
<em>Featuring the best CSS and Flash web sites</em>
</li>
<li>
<a href="www.jb51">N.Design Studio</a>
<em>Blog and design portfolio of WDW designer, Nick La</em>
</li>
</ul>
</body>
</html>
⼆、jquery⿏标滑过显⽰提⽰框实例⼆
⿏标划过⽤户名时,在⿏标右下⾓显⽰div展⽰⽤户资料这个效果
1、效果图
2、实现⽅式
⽆⾮就三⼤块,⼀个是div的定位,这个是该效果的主要难点;⼆个是通过ajax异步加载数据;第三个就是要⽤到两个js属性onmouseover和onmouseout,即⿏标经过和⿏标离开。
3、实现步骤
(1)、⾸先设计好要显⽰⽤户资料的div的样式, 这⾥要注意的该⽅法不是给每个⽤户名的旁边都绑定⼀个div,当⿏标经过时显⽰,⿏标离开时隐藏,⽹页⾥就⼀个显⽰信息的div,哪⾥需要显⽰时就定位在哪
⾥,这要就需要把该div的定位⽅式设置为绝对定位。
HTML代码:
复制代码代码如下:
<div class="blockdiv" id="blockdiv">
<div class="pic">
<img src="../../Users/images/899。png" id="imguserhead" />
</div>
<div class="box">
<table width="220" border="0" >
<tr>
<td >⽤户名:</td>
<td>
<label id="lblusername"></label>
</td>
</tr>
<tr>
<td>真实姓名:</td>
<td>
<label id="lblrealname"></label>
</td>
</tr>
<tr>
<td>性别:</td>
<td>
<label id="sex"></label>
</td>
</tr>
<tr>
<td>所属地区:</td>
<td>
<label id="lbladdress"></label>
</td>
</tr>
<tr>
<td>邮箱:</td>
<td>
<label id="lblemall"></label>
</td>
</tr>
</table>
<div id="messagediv ">正在加载中...</div> </div>
</div>
(2)、相应css代码
复制代码代码如下:
#blockdiv{
width:380px;
height:160px;
float:left;
display:none;
border: 1px solid #ccc; position: absolute; z-index: 1; opacity: 0.1; background: white
}
.pic{
width:100px;
height:100px;
border:1px solid #ccc;
border-radius:10px;
float:left; margin:10px;
overflow:hidden;
}
.box{
width:240px;
height:140px;
margin:10px 0 10px 10px;
float:left;
overflow:hidden;text-overflow:ellipsis; white-space:nowrap;}
(3)、定位,为了能够精确的定位并且能够⽅便的调⽤,所以先在页⾯中放了两个标签,分别⽤于保存当前⿏标的坐标
复制代码代码如下:
<input type="hidden" id="pagex" />
<input type="hidden" id="pagey" />
然后⽤js获取当前坐标并保存到标签中:
复制代码代码如下:
jQuery(document).ready(function ($) {
$(document).mousemove(function (e) {
});
});
(4)、⿏标经过和离开事件js代码
复制代码代码如下:
function ShowInfo(username) {
$("#blockdiv").css({
"display": "block",
"left": ElementById('pagex').value,
"top": ElementById('pagey').value,
});
$("#messagediv").css("display", "block");
$.getJSON("../ashx/GetUserInfo。ashx?name=" + username,
function (data) {
if (data != null) {
$("#lblusername").html(data[0].User_Count)
$("#lblrealname").html(data[0].User_name);
$("#sex").html(data[0].User_Sex);
$("#lbladdress").html(data[0].User_Address)
$("#lblemall").html(data[0].User_Email);
if (data[0].User_HeadImg != null&&data[0].User_HeadImg != "") {
$("#imguserhead").attr("src", "../../Users/" + data[0].String().substring(3));
}
else {
$("#imguserhead").attr("src", "../../Users/images/900.png");
}
$("#messagediv").css("display", "none");
}
else
$("#messagediv").html("未加载到数据!");
});
}
function HiddenInfo() {
$("#blockdiv").css({
"display": "none",
});
$("#lblusername").html("")
$("#lblrealname").html("");
$("#sex").html("");
$("#lbladdress").html("")
$("#lblemall").html("");
}
(5)、调⽤
复制代码代码如下:
<a class="showuserinfo" onmouseover="ShowInfo('<%#Eval("Response_Person") %>')" onmouseout="HiddenInfo()"> jquery⿏标滑过显⽰提⽰框
</a>
希望本⽂所述对⼤家的jQuery程序设计有所帮助。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论