forked from russellsamora/scrollama
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultiple.html
233 lines (202 loc) · 5.74 KB
/
multiple.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js">
<!--<![endif]-->
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Scrollama demo</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
padding: 0;
}
body {
min-height: 101vh;
}
p {
margin: 0;
}
#scroll {
background-color: #cdcdcd;
position: relative;
margin-top: 105vh;
margin-bottom: 200vh;
}
#scroll2 {
background-color: #cdcdcd;
position: relative;
margin-top: 50vh;
margin-bottom: 200vh;
}
.scroll__graphic {
position: absolute;
top: 0;
left: 0;
bottom: auto;
background-color: #ccc;
-moz-transition: background-color 250ms ease-in-out;
-webkit-transition: background-color 250ms ease-in-out;
transition: background-color 250ms ease-in-out;
-webkit-transform: translate3d(0, 0, 0);
-moz-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
.scroll__graphic.is-fixed {
position: fixed;
}
.scroll__graphic.is-bottom {
bottom: 0;
top: auto;
}
.scroll__text {
padding: 1rem;
position: relative;
}
.step {
max-width: 30rem;
margin: 3rem auto;
border: 2px solid #333;
background-color: #fff;
}
.step.is-active {
background-color: lightgoldenrodyellow;
}
.step p {
text-align: center;
padding: 1rem;
}
</style>
</head>
<body>
<section id="scroll">
<div class="scroll__text">
<div class="step" data-step="#ccc">
<p>Step 1</p>
</div>
<!-- <div class='step' data-step='#aaa'>
<p>Step 2</p>
</div> -->
<!-- <div class='step' data-step='#888'>
<p>Step 3</p>
</div>
<div class='step' data-step='#666'>
<p>Step 4</p>
</div> -->
</div>
</section>
<section id="scroll2">
<div class="scroll__text">
<div class="step" data-step="#ccc">
<p>Step 1</p>
</div>
<!-- <div class='step' data-step='#aaa'>
<p>Step 2</p>
</div> -->
<!-- <div class='step' data-step='#888'>
<p>Step 3</p>
</div>
<div class='step' data-step='#666'>
<p>Step 4</p>
</div> -->
</div>
</section>
<div class="debug"></div>
<script src="d3.v4.min.js"></script>
<script src="https://unpkg.com/intersection-observer"></script>
<script src="scrollama.js"></script>
<script>
var container = d3.select("#scroll");
var text = container.select(".scroll__text");
var step = text.selectAll(".step");
var container2 = d3.select("#scroll2");
var text2 = container2.select(".scroll__text");
var step2 = text2.selectAll(".step");
var scroller = scrollama();
var scroller2 = scrollama();
function handleResize() {
// var h = Math.floor(window.innerHeight * 0.75) + 'px'
step.each(function() {
var ran = 0.1 + Math.random();
var h = Math.floor(window.innerHeight * ran) + "px";
d3.select(this).style("height", h);
});
scroller.resize();
}
function handleStepEnter(resp) {
console.log("enter", resp);
step.classed("is-active", function(d, i) {
return i === resp.index;
});
var val = d3.select(resp.element).attr("data-step");
}
function handleStepExit(resp) {
console.log("exit", resp);
d3.select(resp.element).classed("is-active", false);
}
function handleProgress(resp) {
console.log("progress", resp);
}
function handleResize2() {
// var h = Math.floor(window.innerHeight * 0.75) + 'px'
step2.each(function() {
var ran = 0.1 + Math.random();
var h = Math.floor(window.innerHeight * ran) + "px";
d3.select(this).style("height", h);
});
scroller2.resize();
}
function handleStepEnter2(resp) {
console.log("enter", resp);
step2.classed("is-active", function(d, i) {
return i === resp.index;
});
var val = d3.select(resp.element).attr("data-step");
}
function handleStepExit2(resp) {
console.log("exit", resp);
d3.select(resp.element).classed("is-active", false);
}
function handleProgress2(resp) {
console.log("progress", resp);
}
function init() {
handleResize();
handleResize2();
scroller
.setup({
step: "#scroll .step",
offset: 0.33,
debug: true,
progress: true
})
.onStepEnter(handleStepEnter)
.onStepExit(handleStepExit)
.onStepProgress(handleProgress);
scroller2
.setup({
step: "#scroll2 .step",
offset: 0.67,
debug: true,
progress: true
})
.onStepEnter(handleStepEnter2)
.onStepExit(handleStepExit2)
.onStepProgress(handleProgress2);
console.log(scroller.getOffset());
console.log(scroller2.getOffset());
// window.addEventListener('resize', handleResize)
}
init();
</script>
</body>
</html>