-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInfinitescroll.html
95 lines (85 loc) · 3.16 KB
/
Infinitescroll.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Infinite Scrolling Unicode Animals</title>
<style>
body, html {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
overflow: auto;
}
#container {
position: absolute;
top: 0;
left: 0;
width: 10000px;
height: 10000px;
}
.animal {
position: absolute;
font-size: 40px;
white-space: pre;
line-height: 1;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
const container = document.getElementById('container');
const animalEmoji = '🐎';
const legChar = '│';
function createAnimal(x, y) {
const animal = document.createElement('div');
animal.className = 'animal';
animal.style.left = `${x * 300}px`;
animal.style.top = `${y * window.innerHeight}px`;
animal.innerHTML = animalEmoji;
container.appendChild(animal);
return animal;
}
function updateLegs() {
const viewportHeight = window.innerHeight;
const scrollY = window.pageYOffset;
const animals = document.querySelectorAll('.animal');
animals.forEach(animal => {
const animalTop = parseInt(animal.style.top);
const relativePosition = scrollY - animalTop;
const legLength = Math.max(0, Math.min(viewportHeight, relativePosition));
const legsHeight = viewportHeight - legLength;
const emptySpace = ' '.repeat(Math.floor(legsHeight / 20)); // Adjust based on font size
const legs = legChar.repeat(Math.ceil(legLength / 20)); // Adjust based on font size
animal.style.fontSize = '20px'; // Smaller font size for better leg resolution
animal.innerHTML = `${emptySpace}${animalEmoji}\n${legs}`;
});
}
function generateAnimals() {
const viewportWidth = window.innerWidth;
const viewportHeight = window.innerHeight;
const startX = Math.floor(window.pageXOffset / 300);
const endX = startX + Math.ceil(viewportWidth / 300) + 1;
const maxY = Math.ceil((window.pageYOffset + viewportHeight) / viewportHeight) + 1;
for (let x = startX; x < endX; x++) {
for (let y = 0; y < maxY; y++) {
if (!document.querySelector(`.animal[style*="left: ${x * 300}px"][style*="top: ${y * viewportHeight}px"]`)) {
createAnimal(x, y);
}
}
}
}
window.addEventListener('scroll', () => {
generateAnimals();
updateLegs();
});
window.addEventListener('resize', () => {
generateAnimals();
updateLegs();
});
generateAnimals();
updateLegs();
</script>
</body>
</html>