forked from new2code/client-side-web-application
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
97 lines (82 loc) · 2.69 KB
/
Copy pathapp.js
File metadata and controls
97 lines (82 loc) · 2.69 KB
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
96
97
// Simple JavaScript for interactive features
let clickCount = 0;
let currentBackgroundIndex = 0;
// Background color variations
const backgroundClasses = [
"",
"bg-variant-1",
"bg-variant-2",
"bg-variant-3",
"bg-variant-4",
];
// Function to change background color
function changeBackgroundColor() {
// Increment click counter
clickCount++;
document.getElementById("clickCounter").textContent = `Clicks: ${clickCount}`;
// Remove current background class
document.body.className = "";
// Cycle through background variations
currentBackgroundIndex =
(currentBackgroundIndex + 1) % backgroundClasses.length;
// Apply new background class
if (backgroundClasses[currentBackgroundIndex]) {
document.body.classList.add(backgroundClasses[currentBackgroundIndex]);
}
// Add a fun animation effect
document.getElementById("colorButton").style.transform = "scale(0.95)";
setTimeout(() => {
document.getElementById("colorButton").style.transform = "";
}, 150);
}
// Welcome message when page loads
document.addEventListener("DOMContentLoaded", function () {
console.log("🎉 Welcome to your first web app!");
console.log(
"💡 Tip: Open the browser developer tools (F12) to see this message and experiment with the console!",
);
// Add some console styling for fun
console.log(
"%c🚀 Ready for development!",
"color: #667eea; font-size: 16px; font-weight: bold;",
);
// Show a brief welcome animation
document.body.style.opacity = "0";
document.body.style.transition = "opacity 0.5s ease-in";
setTimeout(() => {
document.body.style.opacity = "1";
}, 100);
});
// Fun keyboard shortcut (press 'c' to change colors)
document.addEventListener("keydown", function (event) {
if (event.key.toLowerCase() === "c") {
changeBackgroundColor();
}
});
// Display current time (updates every second)
function updateTime() {
const now = new Date();
const timeString = now.toLocaleTimeString();
// Create time display if it doesn't exist
if (!document.getElementById("currentTime")) {
const timeDisplay = document.createElement("div");
timeDisplay.id = "currentTime";
timeDisplay.style.cssText = `
position: fixed;
top: 10px;
right: 10px;
background: rgba(255, 255, 255, 0.9);
padding: 8px 12px;
border-radius: 20px;
font-size: 0.9rem;
color: #4a5568;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
`;
document.body.appendChild(timeDisplay);
}
document.getElementById("currentTime").textContent =
`Current time: ${timeString}`;
}
// Update time every second
setInterval(updateTime, 1000);
updateTime(); // Initial call