-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_common.js
145 lines (122 loc) · 4.43 KB
/
script_common.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Sticky Navbar Functionality
window.onscroll = function() { stickNavbar(); };
const navbar = document.getElementById("navbar");
const sticky = navbar.offsetTop;
function stickNavbar() {
if (window.pageYOffset > sticky) {
navbar.classList.add("sticky");
} else {
navbar.classList.remove("sticky");
}
}
// Sidebar Navigation Toggle
function openNav() {
document.getElementById("mySidenav").style.width = "415px";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0px";
}
// Particles and Stars Animation
const particleContainer = document.querySelector('.particles');
const starBackground = document.querySelector('.star-background');
for (let i = 0; i < 100; i++) {
const particle = document.createElement('div');
particle.classList.add('particle');
particle.style.top = `${Math.random() * 100}vh`;
particle.style.left = `${Math.random() * 100}vw`;
particle.style.animationDelay = `${Math.random() * 10}s`;
particleContainer.appendChild(particle);
}
for (let i = 0; i < 300; i++) {
const star = document.createElement('div');
star.classList.add('star');
star.style.top = `${Math.random() * 100}vh`;
star.style.left = `${Math.random() * 100}vw`;
starBackground.appendChild(star);
}
// Cursor Effects
const cursor = document.querySelector('.cursor');
const cursorInner = document.querySelector('.cursor2');
const links = document.querySelectorAll('a');
document.addEventListener('mousemove', (e) => {
cursor.style.transform = `translate3d(${e.clientX - 25}px, ${e.clientY - 25}px, 0)`;
cursorInner.style.left = `${e.clientX}px`;
cursorInner.style.top = `${e.clientY}px`;
});
document.addEventListener('mousedown', () => {
cursor.classList.add('click');
cursorInner.classList.add('cursorinnerhover');
});
document.addEventListener('mouseup', () => {
cursor.classList.remove('click');
cursorInner.classList.remove('cursorinnerhover');
});
links.forEach(link => {
link.addEventListener('mouseover', () => {
cursor.classList.add('hover');
});
link.addEventListener('mouseleave', () => {
cursor.classList.remove('hover');
});
});
// FAQ Section Toggle
document.querySelectorAll('.faq-question').forEach(item => {
item.addEventListener('click', () => {
const answer = item.nextElementSibling;
answer.style.display = answer.style.display === 'block' ? 'none' : 'block';
});
});
// Countdown Timer
(function () {
const second = 1000,
minute = second * 60,
hour = minute * 60,
day = hour * 24;
let today = new Date(),
dd = String(today.getDate()).padStart(2, "0"),
mm = String(today.getMonth() + 1).padStart(2, "0"),
yyyy = today.getFullYear(),
nextYear = yyyy + 1,
dayMonth = "11/15/",
birthday = dayMonth + yyyy;
today = mm + "/" + dd + "/" + yyyy;
if (today > birthday) {
birthday = dayMonth + nextYear;
}
const countDown = new Date(birthday).getTime(),
x = setInterval(function() {
const now = new Date().getTime(),
distance = countDown - now;
document.getElementById("days").innerText = Math.floor(distance / day),
document.getElementById("hours").innerText = Math.floor((distance % day) / hour),
document.getElementById("minutes").innerText = Math.floor((distance % hour) / minute),
document.getElementById("seconds").innerText = Math.floor((distance % minute) / second);
if (distance < 0) {
document.getElementById("headline").innerText = "It's my birthday!";
document.getElementById("countdown").style.display = "none";
document.getElementById("content").style.display = "block";
clearInterval(x);
}
}, 0);
}());
// Owl Carousel Slider
$(".slider").owlCarousel({
loop: true,
autoplay: true,
autoplayTimeout: 1000,
autoplayHoverPause: true,
});
// Modal Image Functionality
const modal = document.getElementById("myModal"),
img = document.getElementById("myImg"),
modalImg = document.getElementById("img01"),
captionText = document.getElementById("caption");
img.onclick = function() {
modal.style.display = "block";
modalImg.src = this.src;
captionText.innerHTML = this.alt;
}
const span = document.getElementsByClassName("close")[0];
span.onclick = function() {
modal.style.display = "none";
}