Repository navigation
Expand file tree
/
Copy pathbasic.html
More file actions
143 lines (129 loc) Β· 3.57 KB
/
Copy pathbasic.html
File metadata and controls
143 lines (129 loc) Β· 3.57 KB
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Scrolleo Demo: Basic</title>
<meta
name="description"
content="Scrolleo Demo: Basic step enter/exit functionality"
/>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="style.css" />
<style>
#scrolly {
position: relative;
}
article {
position: relative;
padding: 0 1rem;
margin: 0 auto;
width: 33%;
}
.step {
margin: 2rem auto 4rem auto;
background-color: var(--color-primary-red);
color: var(--color-white);
border-left: 4px solid var(--color-primary-red-dark);
}
.step.is-active {
background-color: var(--color-accent);
color: var(--color-primary);
border-left-color: var(--color-primary-red);
}
.step p {
text-align: center;
padding: 1rem;
font-size: var(--font-size-lg);
}
</style>
</head>
<body>
<main>
<nav>
<a href="index.html">
<img src="scrolleo-mascot.svg" alt="Scrolleo mascot" class="nav-mascot" />
Scrolleo
</a>
<div class="nav__examples">
<p>Examples:</p>
<a href="basic.html">Basic</a>
<a href="progress.html">Progress</a>
<a href="sticky-side.html">Sticky Side</a>
<a href="sticky-overlay.html">Sticky Overlay</a>
<a href="percentage-offset.html">Percentage Offset</a>
<a href="pixel-offset.html">Pixel Offset</a>
<a href="multiple.html">Multiple Instances</a>
<a href="scroll-parent.html">Nested Scroll Container</a>
<a href="performance-test.html">Performance Test</a>
</div>
</nav>
<section id="intro">
<h1 class="intro__hed">Basic Example</h1>
<p class="intro__dek">Start scrolling to see how it works.</p>
</section>
<section id="scrolly">
<article>
<div class="step" data-step="1">
<p>STEP 1</p>
</div>
<div class="step" data-step="2">
<p>STEP 2</p>
</div>
<div class="step" data-step="3">
<p>STEP 3</p>
</div>
<div class="step" data-step="4">
<p>STEP 4</p>
</div>
</article>
</section>
<section id="outro"></section>
</main>
<script src="debug-utils.js"></script>
<script type="module">
import scrolleo from './dist/scrolleo.js';
const scrolly = document.querySelector('#scrolly');
const article = scrolly.querySelector('article');
const steps = article.querySelectorAll('.step');
// Initialize scrolleo
const scroller = scrolleo();
// Setup options
const setupOptions = {
step: '#scrolly article .step',
debug: false,
offset: 0.5,
};
// Event handlers
function handleStepEnter(response) {
// response = { element, direction, index }
console.log(response);
response.element.classList.add('is-active');
}
function handleStepExit(response) {
// response = { element, direction, index }
console.log(response);
response.element.classList.remove('is-active');
}
function init() {
// Set random padding for different step heights (not required)
steps.forEach((step) => {
const v = 100 + Math.floor((Math.random() * window.innerHeight) / 4);
step.style.padding = v + 'px 0px';
});
// Setup scrolleo
scroller
.setup(setupOptions)
.onStepEnter(handleStepEnter)
.onStepExit(handleStepExit);
// Create debug toggle with event handlers
createDebugToggle(scroller, setupOptions, {
onStepEnter: handleStepEnter,
onStepExit: handleStepExit,
});
}
// Initialize
init();
</script>
</body>
</html>