-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
65 lines (59 loc) · 1.74 KB
/
script.js
File metadata and controls
65 lines (59 loc) · 1.74 KB
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
/**
* Sections tak smooth scroll karne ke liye logic
*/
function scrollToSection(id) {
const element = document.getElementById(id);
if (element) {
// 130px offset diya hai taaki navbar section ke title ko na chupaye
const headerOffset = 130;
const elementPosition = element.getBoundingClientRect().top;
const offsetPosition = elementPosition + window.pageYOffset - headerOffset;
window.scrollTo({
top: offsetPosition,
behavior: "smooth"
});
}
}
/**
* Commands copy karne ka logic
*/
function copyText(btn) {
const codeElement = btn.previousElementSibling;
const textToCopy = codeElement.innerText;
navigator.clipboard.writeText(textToCopy).then(() => {
// Button state change
const originalText = btn.innerText;
btn.innerText = "Copied!";
btn.style.background = "#64ffda";
btn.style.color = "#0a192f";
// 1.5 second baad wapas normal kar dena
setTimeout(() => {
btn.innerText = originalText;
btn.style.background = ""; // Wapas CSS wali style
btn.style.color = "";
}, 1500);
}).catch(err => {
console.error("Copy fail ho gaya: ", err);
});
}
/**
* Scroll hone par 'Top' button dikhana ya chupana
*/
window.onscroll = function() {
const topBtn = document.getElementById("topBtn");
// Agar page 400px niche scroll ho gaya hai
if (document.body.scrollTop > 400 || document.documentElement.scrollTop > 400) {
topBtn.style.display = "block";
} else {
topBtn.style.display = "none";
}
};
/**
* Seedha upar jane ke liye
*/
function scrollToTop() {
window.scrollTo({
top: 0,
behavior: "smooth"
});
}