-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
38 lines (29 loc) · 1.01 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
///text to search
function search() {
let textToSearch = document.getElementById("text-to-search").value;
let paragraph = document.getElementById("paragraph");
textToSearch = textToSearch.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
let pattern = new
RegExp(`\\b${textToSearch}\\b`,"gi");
paragraph.innerHTML = paragraph.textContent.replace(pattern, match => `<mark>${match}</mark>`)
}
///sticky header
window.onscroll = function () {myFunction()};
var header = document.getElementById("myHeader");
var sticky = header.offsetTop;
function myFunction() {
if (window.pageYOffset > sticky) {
header.classList.add("sticky");
} else {
header.classList.remove("sticky");
}
}
//search book function in main page
function searchBook() {
var bookName = document.getElementById("text-to-search").value.toLowerCase();
if (bookName === "the alchemist") {
window.location.href = "alchemist.html";
} else if (bookName === "life of pi") {
window.location.href = "lifeofpi.html";
}
}