Write a simple webpage with some javascript animations in one file
- User
Write a simple webpage with some javascript animations in one file
- Assistant
Sure, here's a simple webpage with a few JavaScript animations in one file:
html🌐 Toggle Rendering<!DOCTYPE html> <html> <head> <title>JavaScript Animations</title> <style> body { background-color: #f0f0f0; font-family: Arial, sans-serif; text-align: center; } h1 { color: #333; margin-top: 50px; } .box { background-color: #fff; border-radius: 50%; height: 100px; margin: 0 auto; position: relative; top: 200px; width: 100px; } </style> </head> <body> <h1>JavaScript Animations</h1> <div class="box"></div> <script> var box = document.querySelector('.box'); // Animation 1: move the box to the right function moveRight() { var currentLeft = parseInt(box.style.left || 0, 10); box.style.left = currentLeft + 10 + 'px'; if (currentLeft < 200) { requestAnimationFrame(moveRight); } } // Animation 2: change the box's background color function changeColor() { var currentColor = box.style.backgroundColor || '#fff'; var newColor = currentColor === '#fff' ? '#f00' : '#fff'; box.style.backgroundColor = newColor; setTimeout(changeColor, 500); } // Animation 3: move the box up and down function moveUpDown() { var currentTop = parseInt(box.style.top || 0, 10); var direction = currentTop < 200 ? 1 : -1; box.style.top = currentTop + (direction * 10) + 'px'; requestAnimationFrame(moveUpDown); } // Start the animations moveRight(); setTimeout(changeColor, 1000); moveUpDown(); </script> </body> </html>This webpage has a heading, a white circle, and three JavaScript animations:
- User
Make it simpler
- Assistant
Sure, here's a simpler version of the webpage with just one animation:
html🌐 Toggle Rendering<!DOCTYPE html> <html> <head> <title>JavaScript Animation</title> <style> body { background-color: #f0f0f0; font-family: Arial, sans-serif; text-align: center; } .box { background-color: #fff; border-radius: 50%; height: 100px; margin: 0 auto; position: relative; top: 200px; width: 100px; } </style> </head> <body> <h1>JavaScript Animation</h1> <div class="box"></div> <script> var box = document.querySelector('.box'); // Animation: move the box up and down function moveUpDown() { var currentTop = parseInt(box.style.top || 0, 10); var direction = currentTop < 200 ? 1 : -1; box.style.top = currentTop + (direction * 10) + 'px'; requestAnimationFrame(moveUpDown); } // Start the animation moveUpDown(); </script> </body> </html>