forked from Technigo/project-news-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
64 lines (53 loc) · 1.79 KB
/
script.js
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
// script.js
// Function to handle the back-to-top button
function scrollFunction() {
var backToTopBtn = document.getElementById("backToTopBtn");
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
backToTopBtn.style.display = "block";
} else {
backToTopBtn.style.display = "none";
}
}
// Function to scroll to the top of the page
function scrollToTop() {
window.scrollTo({ top: 0, behavior: 'smooth' });
}
window.onscroll = function () {
scrollFunction();
};
var backToTopBtn = document.getElementById("backToTopBtn");
if (backToTopBtn) {
backToTopBtn.onclick = function () {
scrollToTop();
};
}
// Function to toggle the navigation bar for smaller screens
function toggleNav() {
var nav = document.querySelector('.nav');
nav.classList.toggle('active');
}
// Function to hide the dropdown content
function hideDropdown() {
var dropdownContent = document.querySelector('.dropdown-content');
dropdownContent.style.display = 'none';
}
// Function to show the dropdown content
function showDropdown() {
var dropdownContent = document.querySelector('.dropdown-content');
dropdownContent.style.display = 'block';
}
// Function to open the newsletter popup
function openPopup() {
document.getElementById('newsletterModal').style.display = 'block';
}
// Function to close the newsletter popup
function closePopup() {
document.getElementById('newsletterModal').style.display = 'none';
}
// Newsletter form
document.getElementById('newsletterForm').addEventListener('submit', function (event) {
event.preventDefault();
var email = document.getElementById('email').value;
console.log('Subscribed with email: ' + email);
closePopup();
});