-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadv_dom.js
More file actions
121 lines (110 loc) · 3.62 KB
/
Copy pathadv_dom.js
File metadata and controls
121 lines (110 loc) · 3.62 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
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
//create element
let bt = document.createElement('div');
bt.textContent = 'hello,this is created div.';
bt.classList.add('bt');
bt.style.color = 'red';
document.querySelector('body').append(bt);
console.log(document.querySelector('body').contains(bt));
document.querySelector('.btt').addEventListener('click', () => {
window.scrollBy(100, 0);
if (document.querySelector('body').contains(bt)) bt.remove();
else document.querySelector('body').append(bt);
});
console.log(document.querySelector('.btt').style.color); //to get inline css
console.log(getComputedStyle(document.querySelector('.btt')).color); //to change or get internalor external css
// Get the navbar
const navbar = document.querySelector('.nav');
// Get the offset position of the navbar
const sticky = navbar.offsetTop;
console.log(sticky);
// Add the sticky class to the navbar when you reach its scroll position. Remove the sticky class when you leave the scroll position.
let randomm = (min, max) => {
return Math.floor(Math.random() * (max - min + 1) + min);
};
let randColor = () => {
return `rgb(${randomm(0, 255)},${randomm(0, 255)},${randomm(0, 255)})`;
};
document.querySelector('.div1').addEventListener('click', function (e) {
console.log(randColor());
this.style.backgroundColor = randColor();
});
document.querySelector('.div2').addEventListener('click', function (e) {
this.style.backgroundColor = randColor();
});
document.querySelector('.div3').addEventListener('click', function (e) {
this.style.backgroundColor = randColor();
e.stopPropagation();
});
let navbarr = document.querySelector('.navbar');
navbarr.addEventListener('mouseover', function (e) {
let links = this.children;
links = [...links];
links.forEach((en) => {
if (en !== e.target) en.style.opacity = 0.5;
});
});
navbarr.addEventListener('mouseout', function (e) {
let links = this.children;
links = [...links];
links.forEach((en) => {
if (en !== e.target) en.style.opacity = 1;
});
});
let section1 = document.querySelector('.section1');
// let intialCords = section1.getBoundingClientRect();
// window.addEventListener('scroll', function (e) {
// if (window.scrollY > intialCords.top) {
// navbarr.classList.add('sticky');
// } else {
// navbarr.classList.remove('sticky');
// navbarr.style.backgroundColor = 'black';
// }
// });
const callback = (entries) => {
const [entry] = entries;
if (entry.isIntersecting) {
navbarr.classList.add('sticky');
} else {
navbarr.classList.remove('sticky');
}
};
const options = {
root: null,
threshold: 1,
};
const newObserver = new IntersectionObserver(callback, options);
newObserver.observe(section1);
const callback2 = (entries) => {
const [entry] = entries;
if (entry.isIntersecting) {
entry.target.classList.remove('temp');
} else {
entry.target.classList.add('temp');
}
};
const options2 = {
root: null,
threshold: 0.7,
};
const newObserver2 = new IntersectionObserver(callback2, options2);
let boxes = document.querySelectorAll('.boxes');
boxes.forEach((box) => {
newObserver2.observe(box);
box.classList.add('temp');
});
//slider
let leftbutton = document.querySelector('.btleft');
let rightbutton = document.querySelector('.btright');
let slider1 = document.querySelector('.slider1');
let slider2 = document.querySelector('.slider2');
let slider3 = document.querySelector('.slider3');
let slides = document.querySelectorAll('.slide');
let curSlide = 0;
rightbutton.addEventListener('click', (e) => {
curSlide++;
if (curSlide === slides.length) curSlide = 0;
slides.forEach((slide, i) => {
console.log(slide);
slide.style.transform = `translateX(${(i - curSlide) * 100}%)`;
});
});