基于JQuery的一個(gè)簡單的鼠標(biāo)跟隨提示效果
1.效果如圖
2.實(shí)現(xiàn)思路
1 鼠標(biāo)移入標(biāo)題(這里是<a>標(biāo)簽)
創(chuàng)建一個(gè)div,div的內(nèi)容為鼠標(biāo)位置的文本
將創(chuàng)建好的div加到文檔中
為提示層設(shè)置位置
2 鼠標(biāo)移出標(biāo)題
移除div
3 當(dāng)鼠標(biāo)在標(biāo)題內(nèi)移動時(shí)
同樣添加div效果
3.JQuery實(shí)現(xiàn)代碼
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<style type="text/css">
body
{
font-size:12px;
}
a
{
text-decoration:none;
}
a:hover
{
color:#CC0000;
}
#main
{
margin:100px auto;
width:350px;
height:150px;
border:solid #aaa 1px;
}
.tr_color{
background-color:#aaa;
}
</style>
<script src="../JQuery/jquery-1.4.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$("tr:even").addClass("tr_color");
$("#tb a").mouseover(function(e){
var toolTip = "<div id='tooltip' width='100px' height='12px' style='position:absolute;border:solid #aaa 1px;background-color:#F9F9F9'>" + $(this).html() + "</div>";
$("body").append(toolTip);
$("#tooltip").css({
"top" :e.pageY + "px",
"left" :e.pageX + "px"
});
$("#tb a").mouseout(function(){
$("#tooltip").remove();
});
$("#tb a").mousemove(function(e){
$("#tooltip").css({
"top" :(e.pageY+5) + "px",
"left" :(e.pageX+2) + "px"
});
});
//alert("Y:" + e.pageY + "X:" + e.pageX);
});
});
</script>
<body>
<div id="main">
<h5>JQuery--鼠標(biāo)跟隨提示</h5>
<table id="tb" width="100%">
<tr>
<td><a href="#">中秋快樂11</a></td>
<td><a href="#">中秋快樂12</a></td>
</tr>
<tr>
<td><a href="#">中秋快樂21</a></td>
<td><a href="#">中秋快樂22</a></td>
</tr>
<tr>
<td><a href="#">中秋快樂31</a></td>
<td><a href="#">中秋快樂32</a></td>
</tr>
<tr>
<td><a href="#">中秋快樂41</a></td>
<td><a href="#">中秋快樂42</a></td>
</tr>
<tr>
<td><a href="#">中秋快樂51</a></td>
<td><a href="#">中秋快樂52</a></td>
</tr>
<tr>
<td><a href="#">中秋快樂61</a></td>
<td><a href="#">中秋快樂62</a></td>
</tr>
</table>
</div>
</body>
</html>
代碼很簡單主要是用到了JQuery的三個(gè)事件mouseover,mouseout,mousemove.
相關(guān)文章
jQuery查找節(jié)點(diǎn)并獲取節(jié)點(diǎn)屬性的方法
這篇文章主要介紹了jQuery查找節(jié)點(diǎn)并獲取節(jié)點(diǎn)屬性的方法,涉及jQuery簡單獲取節(jié)點(diǎn)及attr與text方法讀取元素屬性的相關(guān)技巧,需要的朋友可以參考下2016-09-09jQuery實(shí)現(xiàn)鼠標(biāo)可拖動調(diào)整表格列寬度
這篇文章主要介紹了通過jQuery實(shí)現(xiàn)鼠標(biāo)可拖動調(diào)整表格列寬度,需要的朋友可以參考下2014-05-05如何書寫高質(zhì)量jQuery代碼(使用jquery性能問題)
眾所周知,jQuery現(xiàn)在已經(jīng)非常流行,百度新首頁中也已經(jīng)開始使用jQuery,今天總結(jié)下怎么書寫更好的jQuery代碼使jQuery代碼更好、更快的執(zhí)行,希望本篇jQuery教程一改大家以前不合理的做法2014-06-06Jquery調(diào)用webService遠(yuǎn)程訪問出錯(cuò)的解決方法
原來web.config里面默認(rèn)Post設(shè)置是不允許遠(yuǎn)程調(diào)用webservice,需要配置一下就可以了2010-05-05幾種二級聯(lián)動案例(jQuery\Array\Ajax php)
這篇文章主要為大家詳細(xì)介紹了幾種二級聯(lián)動案例(jQuery\Array\Ajax php),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-08-08