DEMO
Press "C" to Change Background Color
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Background Changer</title><link rel="stylesheet" href="styles.css"></head><body><div class="container"><h1>Press "C" to Change Background Color</h1></div><script src="script.js"></script></body></html>
Css
<style>body {margin: 0;padding: 0;font-family: Arial, sans-serif;display: flex;justify-content: center;align-items: center;height: 100vh;background-color: #f0f0f0;transition: background-color 0.5s ease;}.container {text-align: center;}</style>
Js
<script>document.addEventListener('keydown', function(event) {if (event.key === 'c' || event.key === 'C') {changeBackgroundColor();}});function changeBackgroundColor() {var colors = ['#ff5733', '#33ff57', '#5733ff', '#ff33bf', '#33bfff'];var randomColor = colors[Math.floor(Math.random() * colors.length)];document.body.style.backgroundColor = randomColor;}</script>
Contact Us!
0 Comments
type your comment...