add navbar + background + fading text

This commit is contained in:
2024-11-12 23:54:57 +01:00
parent 8ee1039de9
commit c87ecf0428
4 changed files with 185 additions and 15 deletions
+108
View File
@@ -0,0 +1,108 @@
html,
body {
height: 100%; /* Makes html and body elements cover the full viewport height */
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
.image {
background-image: url("https://i.pinimg.com/originals/74/51/5a/74515a5a0b625529e9dd0635ecc8bfcf.jpg"); /* Set your image path here */
background-size: cover; /* Cover the entire container */
background-position: center; /* Center the image */
width: 100vw; /* Full width of the viewport */
height: 100vh; /* Full height of the viewport */
margin-top: 8%;
position: absolute;
text-align: left;
}
#navbar {
overflow: hidden;
background-color: #f1f1f1;
padding: 90px 10px; /* Large padding which will shrink on scroll (using JS) */
transition: 0.4s; /* Adds a transition effect when the padding is decreased */
position: fixed; /* Sticky/fixed navbar */
width: 100%;
top: 0; /* At the top */
z-index: 99;
}
/* Style the navbar links */
#navbar a {
float: left;
color: black;
text-align: center;
padding: 12px;
text-decoration: none;
font-size: 18px;
line-height: 25px;
border-radius: 4px;
}
/* Style the logo */
#navbar #logo {
font-size: 35px;
font-weight: bold;
transition: 0.4s;
}
#navbar a.submenu {
font-size: 2rem;
margin: 0 10px;
transition: 0.4s;
}
/* Links on mouse-over */
#navbar a:hover {
background-color: #ddd;
color: black;
}
/* Display some links to the right */
#navbar-right {
float: right;
margin-right: 3%;
}
/* Add responsiveness - on screens less than 580px wide, display the navbar vertically instead of horizontally */
@media screen and (max-width: 580px) {
#navbar {
padding: 20px 10px !important; /* Use !important to make sure that JavaScript doesn't override the padding on small screens */
}
#navbar a {
float: none;
display: block;
text-align: left;
}
#navbar-right {
float: none;
}
}
/* .typing-message { */
/* text-shadow: 4px 4px 3px rgba(0, 0, 0, 0.1); */
/* color: #fff; */
/* text-align: left; */
/* font-size: 7em; */
/* font-weight: bold; */
/* text-align: center; */
/* margin-top: 40%; */
/* margin-left: -20rem; */
/* /* margin-left: 10px; */
/* } */
.text-container {
position: absolute;
font-family: "Cookie";
font-size: 8rem;
bottom: 30%; /* Adjust vertical position */
left: 20%; /* Adjust horizontal position */
/* transform: translateX(-50%); /* Center horizontally */ */
/* font-size: 2em; */
color: ffffff;
white-space: nowrap;
/* font-family: "Courier New", Courier, monospace; /* Handwritten-like font */ */
/* font-weight: bold; */
/* opacity: 1; /* Start with text hidden */ */
}
+57
View File
@@ -0,0 +1,57 @@
window.onscroll = function () {
scrollFunction();
};
function scrollFunction() {
if (document.body.scrollTop > 80 || document.documentElement.scrollTop > 80) {
document.getElementById("navbar").style.padding = "30px 10px";
document.getElementById("logo").style.fontSize = "25px";
document.getElementById("submenu0").style.fontSize = "1.6rem";
document.getElementById("submenu1").style.fontSize = "1.6rem";
document.getElementById("submenu2").style.fontSize = "1.6rem";
} else {
document.getElementById("navbar").style.padding = "70px 10px";
document.getElementById("logo").style.fontSize = "35px";
document.getElementById("submenu0").style.fontSize = "2rem";
document.getElementById("submenu1").style.fontSize = "2rem";
document.getElementById("submenu2").style.fontSize = "2rem";
}
}
document.addEventListener("DOMContentLoaded", function () {
// The text to display
const text = "Welcome to our site!";
const container = document.getElementById("text-container");
// Function to simulate typing effect
function typeText(element, text, delay = 100) {
let index = 0;
function typeNextChar() {
if (index < text.length) {
// Append the next character
element.innerHTML += text[index];
index++;
// Call the function recursively with a delay
setTimeout(typeNextChar, delay);
}
}
// Start typing
typeNextChar();
element.style.color = "white";
// Fade in the text container after the typing effect starts
setTimeout(() => {
element.style.opacity = 1; // Make the text visible
}, delay * index);
}
// Start typing the text into the container
typeText(container, text, 150); // Adjust delay (in ms) for typing speed
setInterval(() => {
container.innerHTML = ""; // Clear the previous text
container.style.opacity = 0; // Hide the text container
typeText(container, text, 150); // Re-run the typing effect
}, 10000); // 10000ms = 10 seconds
});