-
Notifications
You must be signed in to change notification settings - Fork 7
/
new_file.html
76 lines (68 loc) · 1.62 KB
/
new_file.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
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js文本段落展开和收拢效果</title>
<style>
#container {
margin: 0 auto;
width: 600px;
border: 1px solid #3bb2d0;
}
#wrap {
position: relative;
padding: 10px;
overflow: hidden;
}
#read-more {
padding: 5px;
background: #fff;
color: #333;
}
#read-more a {
padding-right: 22px;
no-repeat 100% 50%;
font-weight: bold;
text-decoration: none;
}
#read-more a: hover {
color: #000;
}
</style>
<script type="text/javascript" src="http://www.codefans.net/ajaxjs/jquery-1.6.2.min.js"></script>
<script type="text/javascript">
$(function() {
var slideHeight = 45; // px 定义折叠的最小高度
var defHeight = $('#wrap').height();
if(defHeight >= slideHeight) {
$('#wrap').css('height', slideHeight + 'px');
$('#read-more').append('<a href="#">更多</a>');
$('#read-more a').click(function() {
var curHeight = $('#wrap').height();
if(curHeight == slideHeight) {
$('#wrap').animate({
height: defHeight
}, "normal");
$('#read-more a').html('折叠');
} else {
$('#wrap').animate({
height: slideHeight
}, "normal");
$('#read-more a').html('更多');
}
return false;
});
}
});
</script>
</head>
<body>
<div id="container">
<div id="wrap">
<div>
<h1>这一段文字是可以折叠展开的,点击下面的“更多”就可以展开,点击下面的“折叠”就可以折叠</h1>
</div>
</div>
<div id="read-more"></div>
</div>
</body>
</html>