Erster Upload
This commit is contained in:
104
emoji/index.html
Normal file
104
emoji/index.html
Normal file
@@ -0,0 +1,104 @@
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<style>
|
||||
body {
|
||||
background-color: white; /* Ensure the iframe has a white background */
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Emoji Gravity and Collision</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
.emoji {
|
||||
position: absolute;
|
||||
font-size: 24px;
|
||||
user-select: none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
const emojis = ['😀', '😂', '😊', '😉', '😎', '😍', '🤔', '😜', '🥳', '🤩'];
|
||||
|
||||
function getRandomEmoji() {
|
||||
return emojis[Math.floor(Math.random() * emojis.length)];
|
||||
}
|
||||
|
||||
function getRandomInt(min, max) {
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
}
|
||||
|
||||
class Emoji {
|
||||
constructor(x, y) {
|
||||
this.element = document.createElement('div');
|
||||
this.element.className = 'emoji';
|
||||
this.element.textContent = getRandomEmoji();
|
||||
document.body.appendChild(this.element);
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.vx = (Math.random() - 0.5) * 2; // Random horizontal velocity
|
||||
this.vy = (Math.random() - 0.5) * 2; // Random vertical velocity
|
||||
this.ax = 0;
|
||||
this.ay = 0.1; // Gravity acceleration
|
||||
|
||||
this.updatePosition();
|
||||
}
|
||||
|
||||
updatePosition() {
|
||||
this.vx += this.ax;
|
||||
this.vy += this.ay;
|
||||
|
||||
this.x += this.vx;
|
||||
this.y += this.vy;
|
||||
|
||||
if (this.y + this.element.offsetHeight > window.innerHeight) {
|
||||
this.y = window.innerHeight - this.element.offsetHeight;
|
||||
this.vy *= -0.7; // Bounce effect
|
||||
}
|
||||
|
||||
if (this.x + this.element.offsetWidth > window.innerWidth || this.x < 0) {
|
||||
this.vx *= -0.7; // Bounce effect
|
||||
}
|
||||
|
||||
this.element.style.left = `${this.x}px`;
|
||||
this.element.style.top = `${this.y}px`;
|
||||
|
||||
requestAnimationFrame(() => this.updatePosition());
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('click', (event) => {
|
||||
const count = getRandomInt(3, 7);
|
||||
for (let i = 0; i < count; i++) {
|
||||
new Emoji(event.clientX, event.clientY);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
Reference in New Issue
Block a user