-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
100 lines (89 loc) · 2.54 KB
/
index.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
<html>
<head>
<style>
* {
box-sizing: border-box;
}
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
.long {
height: 500px;
border: 1px solid black;
overflow: auto;
}
.long-container {
height: 5000px;
border: 1px solid black;
position: relative;
}
.segment {
top: 2000px;
width: 100%;
height: 200px;
border: 1px solid black;
position: absolute;
}
.text {
pointer-events: none;
/*top: 50%;*/
will-change: transform;
width: 100%;
/*transform: translateY(-50%);*/
/*position: absolute;*/
}
</style>
</head>
<body>
<div id="app">
<div class="long" v-on:scroll="scrollHandler" id="onscroll">
<div class="long-container">
<div class="segment">
<div class="text" v-bind:style="style" id="styled">
Text
</div>
</div>
</div>
</div>
</div>
</body>
<script>
let scrolled = 0;
const segmentHeight = 200;
const toScroll = document.querySelector('#onscroll');
const styled = document.querySelector('#styled');
toScroll.addEventListener('scroll', scrollHandler);
console.log({ toScroll, styled })
function scrollHandler(event) {
console.log(event.target.scrollTop);
scrolled = event.target;
const segmentStart = 0;
const segmentEnd = segmentStart + segmentHeight;
const scrollTop = event.target.scrollTop;
let style = {};
if (scrollTop < 1500) {
} else if (scrollTop < 1700) {
style = {
transform: `translateY(${(scrollTop - 1500) / 2}px)translateY(-50%)`
}
} else if (scrollTop < 2000) {
style = {
transform: 'translateY(100px)translateY(-50%)'
}
} else if (scrollTop < 2200) {
style = {
transform: `translateY(${(scrollTop - 2000 + 200) / 2}px)translateY(-50%)`
}
} else {
style = {
}
}
Object.assign(styled.style, style);
}
</script>
</html>