Skip to content

Commit 567e155

Browse files
adding unobserver usage to this example
1 parent b3a3e8d commit 567e155

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

resize-observer/resize-observer-text.html

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,18 @@
4848
form input {
4949
flex: 3;
5050
}
51+
52+
input[type="checkbox"] {
53+
height: 2rem;
54+
}
5155
</style>
5256
</head>
5357
<body>
5458
<div>
5559
<h1>So what happened?</h1>
5660
<p>And remember, don't do anything that affects anything, unless it turns out you were supposed to, in which case, for the love of God, don't not do it! Ow, my spirit! I don't want to be rescued. You guys aren't Santa! You're not even robots. I've got to find a way to escape the horrible ravages of youth. Suddenly, I'm going to the bathroom like clockwork, every three hours. And those jerks at Social Security stopped sending me checks. Now 'I' have to pay 'them'!</p>
5761
<form>
62+
<div><label>Observer enabled:</label><input type="checkbox" checked></div>
5863
<div><label>Adjust width:</label><input type="range" value="600" min="300" max="1300"></div>
5964
</form>
6065
</div>
@@ -63,7 +68,8 @@ <h1>So what happened?</h1>
6368
const h1Elem = document.querySelector('h1');
6469
const pElem = document.querySelector('p');
6570
const divElem = document.querySelector('body > div');
66-
const slider = document.querySelector('input');
71+
const slider = document.querySelector('input[type="range"]');
72+
const checkbox = document.querySelector('input[type="checkbox"]');
6773

6874
divElem.style.width = '600px';
6975

@@ -84,6 +90,14 @@ <h1>So what happened?</h1>
8490
});
8591

8692
resizeObserver.observe(divElem);
93+
94+
checkbox.addEventListener('change', () => {
95+
if(checkbox.checked) {
96+
resizeObserver.observe(divElem);
97+
} else {
98+
resizeObserver.unobserve(divElem);
99+
}
100+
});
87101
}
88102
</script>
89103
</body>

0 commit comments

Comments
 (0)