|
<script> |
|
// Generate the Winter 2003/2004 Sale Banner |
|
document.addEventListener("DOMContentLoaded", function() { |
|
// Create bannerDiv to hold all the contents of the banner |
|
const bannerDiv = document.createElement("div"); |
|
bannerDiv.id = "winter-2004-banner"; |
|
bannerDiv.className = "winter-2004-banner"; |
|
|
|
// Add column 1 content to bannerDiv |
|
const divCol1 = document.createElement("div"); |
|
divCol1.id = "column-1"; |
|
const divHeading = document.createElement("h2"); |
|
divHeading.className = "winter-2004-banner-heading"; |
|
divHeading.textContent = "WINTER SAVINGS Start Now!"; |
|
divCol1.appendChild(divHeading); |
|
const divParagraph = document.createElement("p"); |
|
divParagraph.className = "winter-2004-banner-text"; |
|
divParagraph.textContent = |
|
"50% off any bundle. Take advantage while it lasts!"; |
|
divCol1.appendChild(divParagraph); |
|
bannerDiv.appendChild(divCol1); |
|
|
|
// Add column 2 content to bannerDiv |
|
const divCol2 = document.createElement("div"); |
|
divCol2.id = "column-2"; |
|
const divButton = document.createElement("div"); |
|
divButton.className = "winter-2004-banner-button"; |
|
const divLink = document.createElement("a"); |
|
divLink.href = "https://mysupercoolsite.site/2024-winter-sale"; |
|
divLink.textContent = "Get 50% Off Now!"; |
|
divButton.appendChild(divLink); |
|
divCol2.appendChild(divButton); |
|
bannerDiv.appendChild(divCol2); |
|
document.body.insertBefore(bannerDiv, document.body.firstChild); |
|
}); |
|
|
|
// Since we're "fixing" this banner to the top, let's be polite and show it only when people are at the top of the page. |
|
window.addEventListener('scroll', function() { |
|
const bannerDiv = document.querySelector("#winter-2004-banner"); |
|
let currentScrollTop = document.documentElement.scrollTop || window.pageYOffset; |
|
|
|
if (currentScrollTop === 0) { |
|
// Show |
|
bannerDiv.style.display = 'flex'; |
|
} else { |
|
// Hide |
|
bannerDiv.style.display = 'none'; |
|
} |
|
|
|
}); |
|
</script> |
Note: The JavaScript code for the banner does not use
document.write()
.https://developer.mozilla.org/en-US/docs/Web/API/Document/write