-
Notifications
You must be signed in to change notification settings - Fork 0
/
jq-dom4.html
78 lines (75 loc) · 1.93 KB
/
jq-dom4.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>图片链接提示效果</title>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<style type="text/css">
body{
margin:0;
padding:40px;
background:#fff;
font:80% Arial, Helvetica, sans-serif;
color:#555;
line-height:180%;
}
img{border:none;}
ul,li{
margin:0;
padding:0;
}
li{
list-style:none;
float:left;
display:inline;
margin-right:10px;
border:1px solid #AAAAAA;
}
/* tooltip */
#tooltip{
position:absolute;
border:1px solid #ccc;
background:#333;
padding:2px;
display:none;
color:#fff;
}
</style>
</head>
<body>
<h1>效果图</h1>
<ul>
<li><a href="images/apple_1_bigger.jpg" class="tooltip" title="苹果 ipod" ><img src="images/apple_1.jpg" alt="苹果 ipod"></a></li>
<li><a href="images/apple_2_bigger.jpg" class="tooltip" title="苹果 nano" ><img src="images/apple_2.jpg" alt="苹果 nano"></a></li>
<li><a href="images/apple_3_bigger.jpg" class="tooltip" title="苹果 iphone" ><img src="images/apple_3.jpg" alt="苹果 iphone"></a></li>
<li><a href="images/apple_4_bigger.jpg" class="tooltip" title="苹果 Mac" ><img src="images/apple_4.jpg" alt="苹果 Mac"></a></li>
</ul>
<script>
$(function() {
x = 10;
y = 20;
$("a.tooltip").mouseover(function(e) {
this.Mytitle = this.title;
this.title = "";
var imgTitle = this.Mytitle? "</br>"+this.Mytitle :"";
var tooltip = "<div id='tooltip'><img src='"+this.href+"' alt='产品预览图'>"+imgTitle+"</div>";
$("body").append(tooltip);
$("#tooltip").css({
"top":(e.pageY+y) + "px",
"left":(e.pageX+x) + "px"
}).show("fast");
})
.mouseout(function() {
this.title = this.Mytitle;
$("#tooltip").remove();
})
.mousemove(function(e) {
$("#tooltip").css({
"top":(e.pageY+y) + "px",
"left":(e.pageX+x) + "px"
});
});
})
</script>
</body>
</html>