Skip to content

Commit 397f5fb

Browse files
author
Yanbin Ma
committed
增加弹性盒模型
1 parent e07061c commit 397f5fb

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

demo/scroll-top.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<meta charset="UTF-8">
55
<title>Scroll Top</title>
66
<style>
7-
.container { margin: 0 auto; width: 980px; height: 1000px; background-color: #f9f9f9; }
8-
.scrolltop { position: fixed; bottom: 10px; left: 50%; margin-left: 500px; width: 30px; height: 30px; background-color: #fae321; }
7+
.container { margin: 0 auto; width: 980px; height: 1000px; }
8+
.scrolltop { position: fixed; bottom: 10px; left: 50%; margin-left: 500px; width: 30px; height: 30px; background-color: #3d9970; cursor: pointer; }
99
</style>
1010
</head>
1111
<body>

demo/sticky.html

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Sticky</title>
6+
<style>
7+
body { margin: 0; }
8+
.container-fluid { height: 150px; background-color: #39cccc; }
9+
.container { margin: 0 auto; width: 980px; display: flex; }
10+
.container .main { width: 800px; flex: 1; }
11+
.container .main .section { height: 400px; }
12+
.container .sidebar { padding: 20px; flex: 0 0 180px; }
13+
.container .sidebar .elevator { height: 300px; border: 1px soild #aaaaaa; border-radius: 3px; }
14+
.sticky { position: fixed; top: 0; }
15+
</style>
16+
</head>
17+
<body>
18+
<div class="container-fluid" id="heading"></div>
19+
<div class="container">
20+
<div class="main">
21+
<div class="section" style="background-color: #0074d9"></div>
22+
<div class="section" style="background-color: #ff4136"></div>
23+
<div class="section" style="background-color: #01ff70"></div>
24+
<div class="section" style="background-color: #001f3f"></div>
25+
<div class="section" style="background-color: #f012be"></div>
26+
</div>
27+
<div class="sidebar"></div>
28+
</div>
29+
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
30+
<script type="text/javascript">
31+
$(function () {
32+
33+
$(window).on('scroll', function () {
34+
if ($(this).scrollTop() > $('#heading').offset().top) {
35+
$('.sidebar').addClass('sticky');
36+
} else {
37+
$('.sidebar').removeClass('sticky');
38+
}
39+
});
40+
})
41+
</script>
42+
</body>
43+
</html>

0 commit comments

Comments
 (0)