-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
150 lines (122 loc) · 4.98 KB
/
index.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
146
147
148
149
150
// share buttons
const share_twitter = document.querySelector(".share-twitter");
const share_facebook = document.querySelector(".share-facebook");
const share_linkedIn = document.querySelector(".share-linkedIn");
const share_reddit = document.querySelector(".share-reddit");
const pageUrl = "https://sola0404.github.io/6780_Ass/";
const message = "Let's meet Bunny Kingdom together!";
const twitterAPI = `https://twitter.com/intent/tweet?text=${pageUrl}. ${message}`;
share_twitter.addEventListener("click", () => {
console.log("clickwed");
window.open((url = twitterAPI), (target = "blank"));
});
const facebookAPI = `https://www.facebook.com/share.php?u=${pageUrl}`;
share_facebook.addEventListener("click", () => {
window.open((url = facebookAPI), (target = "blank"));
});
const linkedInAPI = `https://www.linkedin.com/sharing/share-offsite/?url=${pageUrl}`;
share_linkedIn.addEventListener("click", () => {
window.open((url = linkedInAPI), (target = "blank"));
});
const redditAPI = `https://www.reddit.com/submit?url=${pageUrl}&title=bunnykingdom`;
share_reddit.addEventListener("click", () => {
window.open((url = redditAPI), (target = "blank"));
});
// get behavior tag element
const tag = document.getElementById("behavior-tag");
const teemo = document.getElementById("teemo");
// set mouse over event to every behavior part
document.getElementById("binky").addEventListener("mouseover", () => {
tag.innerText = "Binky";
});
document.getElementById("ear-shaking").addEventListener("mouseover", () => {
tag.innerHTML = "<h2>Ear<br>Shaking</h2>";
});
document.getElementById("zooming").addEventListener("mouseover", () => {
tag.innerText = "Zooming";
});
document.getElementById("purring").addEventListener("mouseover", () => {
tag.innerText = "Purring";
teemo.setAttribute("src", "Images/Teemo-behaviors/purring.jpg");
});
document.getElementById("grooming").addEventListener("mouseover", () => {
tag.innerText = "Grooming";
teemo.setAttribute("src", "Images/Teemo-behaviors/grooming.jpg");
});
document.getElementById("sprawling").addEventListener("mouseover", () => {
tag.innerText = "Sprawling";
teemo.setAttribute("src", "Images/Teemo-behaviors/sprawling.jpg");
});
document.getElementById("flopping").addEventListener("mouseover", () => {
tag.innerText = "Flopping";
teemo.setAttribute("src", "Images/Teemo-behaviors/flopping.jpg");
});
document.getElementById("loafing").addEventListener("mouseover", () => {
tag.innerText = "Loafing";
teemo.setAttribute("src", "Images/Teemo-behaviors/loafing.jpg");
});
// top button
const topButton = document.getElementById("top-btn");
// When the user scrolls down 20px from the top of the document, show the button
window.onscroll = function () {
scrollFunction();
};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
topButton.style.display = "block";
} else {
topButton.style.display = "none";
}
}
// When the user clicks on the button, scroll to the top of the document
function topFunction() {
document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
}
// accordion
const accordionItemHeaders = document.querySelectorAll(
".accordion-item-header"
);
accordionItemHeaders.forEach((accordionItemHeader) => {
accordionItemHeader.addEventListener("click", () => {
// only allow one item be shown at one time
const currentlyActiveAccordionItemHeader = document.querySelector(
".accordion-item-header.active"
);
if (
currentlyActiveAccordionItemHeader &&
currentlyActiveAccordionItemHeader !== accordionItemHeader
) {
currentlyActiveAccordionItemHeader.classList.toggle("active");
currentlyActiveAccordionItemHeader.nextElementSibling.style.maxHeight = 0;
}
accordionItemHeader.classList.toggle("active");
const accordionItemBody = accordionItemHeader.nextElementSibling;
if (accordionItemHeader.classList.contains("active")) {
accordionItemBody.style.maxHeight = accordionItemBody.scrollHeight + "px";
} else {
accordionItemBody.style.maxHeight = 0;
}
});
});
// // social buttons
const twitter = document.querySelector(".twitter");
const github = document.querySelector(".github");
const facebook = document.querySelector(".facebook");
const linkedin = document.querySelector(".linkedin");
const twitterUrl = `https://twitter.com/0404Yujia`;
twitter.addEventListener("click", () => {
window.open((url = twitterUrl), (target = "blank"));
});
const githubUrl = `https://github.com/Sola0404`;
github.addEventListener("click", () => {
window.open((url = githubUrl), (target = "blank"));
});
const facebookUrl = `https://www.facebook.com/profile.php?id=100077606209747`;
facebook.addEventListener("click", () => {
window.open((url = facebookUrl), (target = "blank"));
});
const linkedinUrl = `https://www.linkedin.com/in/yujia-chen-886920253/`;
linkedin.addEventListener("click", () => {
window.open((url = linkedinUrl), (target = "blank"));
});