-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
70 lines (68 loc) · 2.1 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
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<style>
body {
display: flex;
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
#left {
position: sticky;
top: 0;
width: 30%;
height: 100vh;
overflow: auto;
padding: 20px;
box-sizing: border-box;
}
#right {
width: 70%;
padding: 20px;
box-sizing: border-box;
}
</style>
<script>
$(document).ready(function() {
$(document).scroll(function() {
$('#right h2').each(function() {
var topDistance = $(this).offset().top - $(window).scrollTop();
var leftId = $(this).attr('id').replace('right', 'left');
if(topDistance >= 0 && topDistance <= 200) {
$('#' + leftId).css('font-size', '2em');
} else {
$('#' + leftId).css('font-size', '1em');
}
});
});
});
</script>
</head>
<body>
<div id="left">
</div>
<div id="right">
</div>
<script>
const left = document.getElementById('left');
const right = document.getElementById('right');
const createChild = (type, id, inner) => {
child = document.createElement(type);
if (id !== null) child.setAttribute('id', id);
child.innerHTML = inner;
return child;
}
for (i = 1; i <= 12; i++) {
left.appendChild(createChild('h2', `leftHeading${i}`, `<a href="#rightHeading${i}">Heading ${i}</a>`));
// automate what happens in right
right.appendChild(createChild('h2', `rightHeading${i}`, `Heading ${i}`));
for (j = 1; j <= 3; j++) {
right.appendChild(createChild('p', null, `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris posuere dui sem, id mollis purus feugiat non.`));
}
}
right.innerHTML += '<div style="height: 600px"></div>';
</script>
</body>
</html>