-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
126 lines (116 loc) · 5.06 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
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
document.addEventListener('DOMContentLoaded', function() {
if (window.location.hash === "#hakkimizda") {
var hakkimizdaSection = document.getElementById("hakkimizda");
if (hakkimizdaSection) {
var yOffset = hakkimizdaSection.getBoundingClientRect().top + window.pageYOffset;
window.scrollTo({ top: yOffset, behavior: 'smooth', });
}
}
if (window.location.hash === "#urunler") {
var hakkimizdaSection = document.getElementById("urunler");
if (hakkimizdaSection) {
var yOffset = hakkimizdaSection.getBoundingClientRect().top + window.pageYOffset;
window.scrollTo({ top: yOffset, behavior: 'smooth' });
}
}
if (window.location.hash === "#iletisim") {
var hakkimizdaSection = document.getElementById("iletisim");
if (hakkimizdaSection) {
var yOffset = hakkimizdaSection.getBoundingClientRect().top + window.pageYOffset;
window.scrollTo({ top: yOffset, behavior: 'smooth' });
}
}
if (window.location.hash === "#placeUn") {
var hakkimizdaSection = document.getElementById("placeun");
if (hakkimizdaSection) {
var yOffset = hakkimizdaSection.getBoundingClientRect().top + window.pageYOffset;
window.scrollTo({ top: yOffset, behavior: 'smooth' });
}
}
});
function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length === 2) return parts.pop().split(";").shift();
}
function toggleTheme() {
var body = document.body;
var isDarkTheme = body.classList.contains("dark");
if (isDarkTheme) {
document.cookie = "theme=light";
} else {
document.cookie = "theme=dark";
}
}
const showOnPx = 150;
const backToTopButton = document.querySelector(".back-to-top");
const goToBottomButton = document.querySelector(".go-to-bottom");
document.body.onload = function () {
if (scrollContainer().scrollTop > showOnPx) {
backToTopButton.classList.remove("hidden");
goToBottomButton.classList.add("hidden");
} else {
backToTopButton.classList.add("hidden");
goToBottomButton.classList.remove("hidden");
}
if (getCookie("theme") !== null) {
document.body.classList.value = getCookie("theme");
if (getCookie("theme") === "light") {
document.querySelector(".horizontal-menu").style.backgroundColor = "white";
document.querySelector("#name").style.color = "black";
document.querySelector("#email").style.color = "black";
document.querySelector("#sub").style.color = "black";
document.querySelector("#body").style.color = "black";
document.querySelector("footer").style.backgroundColor = "white";
}
} else {
document.body.classList.value = "dark";
document.querySelector(".horizontal-menu").style.backgroundColor = "black";
document.querySelector("#name").style.color = "white";
document.querySelector("#email").style.color = "white";
document.querySelector("#sub").style.color = "white";
document.querySelector("#body").style.color = "white";
document.querySelector("footer").style.backgroundColor = "black";
}
}
const scrollContainer = () => {
return document.documentElement || document.body;
};
document.addEventListener("scroll", () => {
if (scrollContainer().scrollTop > showOnPx) {
backToTopButton.classList.remove("hidden");
} else {
backToTopButton.classList.add("hidden");
goToBottomButton.classList.remove("hidde");
}
})
const goToTop = () => {
document.body.scrollIntoView({
behavior: "smooth",
});
};
const goToBottom = () => {
window.scrollTo(0, document.body.scrollHeight)
}
backToTopButton.addEventListener("click", goToTop);
goToBottomButton.addEventListener("click", goToBottom);
document.querySelector(".theme").addEventListener("click", function () {
toggleTheme();
if (document.body.classList.value === "dark") {
document.body.classList.value = "light";
document.querySelector(".horizontal-menu").style.backgroundColor = "white";
document.querySelector("#name").style.color = "black";
document.querySelector("#email").style.color = "black";
document.querySelector("#sub").style.color = "black";
document.querySelector("#body").style.color = "black";
document.querySelector("footer").style.backgroundColor = "white";
} else {
document.body.classList.value = "dark";
document.querySelector(".horizontal-menu").style.backgroundColor = "black";
document.querySelector("#name").style.color = "white";
document.querySelector("#email").style.color = "white";
document.querySelector("#sub").style.color = "white";
document.querySelector("#body").style.color = "white";
document.querySelector("footer").style.backgroundColor = "black";
}
})