Custom Wishes Website Code

Fri Jan 26, 2024

YouTube Tutorial

Link: 

Link to the website that I hosted : https://vb-republic-wishes.tiiny.site/

Code

index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<script src="https://cdn.jsdelivr.net/npm/canvas-confetti@1.0.1"></script>
<title>Republic Day Wishes</title>
</head>
<body>
<div class="container">
<div id="wishesContent">
<h1>Happy Republic Day!</h1>
<div id="wishesOutput"></div>
</div>

<form id="wishesForm">
<label for="name">Enter Your Name:</label>
<input type="text" id="name" name="name" required>

<button type="button" onclick="generateWishes()">Generate Wishes</button>
</form>
</div>

<script src="script.js"></script>
</body>
</html>

styles.css

body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #530249;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
color: #000000;
}

.container {
background-color: #f9f9f9;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
text-align: center;
}

#wishesContent {
background: linear-gradient(to bottom, #ff9933, #fff, #138808); /* Indian tricolor background */
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
margin-bottom: 20px;
opacity: 0;
transform: translateY(-20px);
animation: popperAnimation 0.8s ease-out forwards;
}

@keyframes popperAnimation {
from {
opacity: 0;
transform: translateY(-20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}

h1 {
font-size: 2em;
margin-bottom: 20px;
color: #000000;
}

form {
display: grid;
gap: 10px;
}

label {
font-weight: bold;
color: #000000;
}

input {
padding: 10px;
border: none;
border-radius: 4px;
font-size: 1em;
}

button {
background-color: #138808;
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
}

button:hover {
background-color: #117c06;
}

#wishesOutput {
margin-top: 20px;
}

#wishesContent p {
font-size: 1.4em;
line-height: 1.2;
color: #000000;
}

img {
max-width: 100%;
border-radius: 8px;
margin-top: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}

script.js

function generateConfetti() {
const wishesContent = document.getElementById('wishesContent');

confetti({
particleCount: 100,
spread: 70,
origin: { y: 0.6 }
});

setTimeout(() => {
wishesContent.style.opacity = '1';
wishesContent.style.transform = 'translateY(0)';
}, 500);
}

function generateWishes() {
const name = document.getElementById('name').value;
const wishesOutput = document.getElementById('wishesOutput');
const wishesForm = document.getElementById('wishesForm');

wishesOutput.innerHTML = `
<p>Dear Indian,</p>
<p>Wishing you a Happy Republic Day! 🇮🇳</p>
<p>May the tricolor always fly high. Jai Hind!</p>
<p>- From ${name}</p>
`;

wishesForm.style.display = 'none';

generateConfetti();

const urlWithQuery = window.location.href.split('?')[0] + `?name=${encodeURIComponent(name)}`;
window.history.replaceState({}, document.title, urlWithQuery);
}

window.onload = function () {
const urlParams = new URLSearchParams(window.location.search);
const nameParam = urlParams.get('name');

if (nameParam) {
document.getElementById('name').value = decodeURIComponent(nameParam);
generateWishes();
}
};