/
sticky.html
144 lines (130 loc) · 3.87 KB
/
sticky.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!DOCTYPE html>
<!--
Copyright 2012 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Author: Eric Bidelman (ericbidelman@chromium.org)
-->
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro' rel='stylesheet' type='text/css'>
<link href="../common.css" rel="stylesheet" type="text/css" media="all">
<title>position: sticky</title>
<style>
html, body {
overflow: initial;
background: none;
}
body {
box-sizing: border-box;
margin: 0 150px;
font-family: 'Source Sans Pro', sans-serif;
}
.sticky {
position: -webkit-sticky;
position: -moz-sticky;
position: -o-sticky;
position: -ms-sticky;
position: sticky;
top: 10px;
z-index: 1;
}
[data-lorem] {
margin-top: 2em;
line-height: 1.5;
text-align: justify;
background: #eee;
border-radius: 5px;
padding: 15px;
}
[data-lorem] .sticky {
background: #3A5E8C;
padding: 15px 10px;
color: white;
border-radius: 5px;
display: inline-block;
width: 100%;
box-sizing: border-box;
}
[data-lorem] h2 {
float: left;
margin: 0;
}
[data-lorem] img {
float: right;
margin-top: 5px;
}
.nosupport {
color: darkred;
font-weight: bold;
display: none;
text-align: center;
}
</style>
</head>
<body>
<details>
<summary>What's this?</summary>
<div>
<p>An example of <code>position: sticky</code> as proposed on <a href="http://lists.w3.org/Archives/Public/www-style/2012Jun/0627.html" target="_blank">www-style</a>.</p>
<p>Watch as the blue title bars remain in the viewport at <code>top: 10px</code> until their parent no longer fits.
All thanks to <code>position: sticky</code>. There are no <code>scroll</code> handlers on this page.</p>
<p><b>Support:</b> Chromium 23.0.1247.0 and WebKit nightly.</p>
</div>
</details>
<p style="text-align:center;font-weight: bold;">Scroll this page.</p>
<p class="nosupport">Your browser does not support <code>position: sticky</code>!!</p>
<div data-lorem="p">
<span class="sticky"><h2>No</h2><img src="http://www.html5rocks.com/static/images/share.png" title="Just an example"></span>
</div>
<script src="lorem.js"></script>
<script>
if (!window.getComputedStyle(document.querySelector('.sticky')).position.match('sticky')) {
document.querySelector('.nosupport').style.display = 'block';
}
var MSGS = [
'JavaScript',
'scroll events',
'control',
'this',
'positioning!'
];
function init() {
var content = document.querySelector('[data-lorem]');
var lorem = new Lorem();
lorem.type = Lorem.TEXT;
lorem.query = '3p';
lorem.createLorem(content);
MSGS.forEach(function(msg, i) {
var clone = content.cloneNode(true);
clone.querySelector('h2').textContent = msg;
document.body.appendChild(clone);
});
}
init();
</script>
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22014378-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<!--[if IE]>
<script src="http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js"></script>
<script>CFInstall.check({mode: 'overlay'});</script>
<![endif]-->
</body>
</html>