超链接提示效果

html:

<!DOCTYPE >
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style type="text/css">
* {
margin: 0px;
padding: 0;
font-family: "微软雅黑", "arial", " sans-serif";
font-size: 16px;
}

body {
margin: 20px;
}

.tooltip {
border: 1px solid #333;
background: #f7f5d1;
padding: 1px;
color: #333;
margin: 20px;
}
</style>
<script type="text/javascript" src="js/jquery-2.2.2.min.js">
</script>

<script type="text/javascript">
$(function () {
var x = 10;
var y = 20;
// 设置鼠标滑入超级链接时的处理方法
$("a .tooltip").mouseover(function () {
this.myTitle = this.title;
this.title = "";
//创建div元素
var oTooltip = "<div id='tooltip'>" + this.myTitle + "</div>";
$("body").append(oTooltip);
// 设置x坐标和y坐标并且显示.e指jquery中获取鼠标在页面上的位置。x是光标离左边的位置 y是离上边的位置,这段代码就是用jquery来设置id为tooltip的元素在body中的显示位置,显示位置在鼠标位置旁边。
$("#tooltip").css({
"top": (e.pageY + y) + "px",
"left": (e.pageX + x) + "px"
}).show("fast");
}).mouseout(function () {
this.title = this.myTitle;
$("#tooltip").remove();
}).mousemove(function () {
$("#tooltip").css({
"top": (e.pageY + y) + "px",
"left": (e.pageX + x) + "px"
});
})
})
</script>
</head>

<body>
<p><a href="" class="tooltip" title="超链接提示1">提示1.</a></p><br/>

<p><a href="" class="tooltip" title="超链接提示2">提示2.</a></p>

</body>

</html>

result:

运行:

原文地址:https://www.cnblogs.com/theWayToAce/p/5495848.html