Skip to content

Commit faa417e

Browse files
committed
docs(demo): optimized dynamic images example
1 parent 1b6e007 commit faa417e

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

demo/index.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@
3131
body > main iframe {
3232
margin: 1rem;
3333
}
34+
/* dynamically added images */
35+
.add-image ~ div {
36+
min-height: 100vh;
37+
position: relative;
38+
}
39+
.add-image ~ div img {
40+
position: absolute;
41+
bottom: 0;
42+
}
3443

3544
/* Displaying the images on smaller viewports */
3645
img {
@@ -163,7 +172,13 @@ <h1>
163172
</noscript>
164173

165174
<h2>dynamic images</h2>
166-
<button type="button" class="add-image">Add image</button>
175+
<p>
176+
Add <code>div</code> element and image underneath (scroll down after
177+
pressing the following button)
178+
</p>
179+
<button type="button" class="add-image">
180+
Add dynamic image underneath
181+
</button>
167182
</main>
168183
<!-- Including other optional polyfills depending on expected browser support scope -->
169184
<script

demo/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import loadingAttributePolyfill from '../dist/loading-attribute-polyfill.module.
22

33
// Test for dynamically inserted images
44
let addImage = (event) => {
5-
let noscriptElement = document.createElement('noscript'),
5+
let divElement = document.createElement('div'),
6+
noscriptElement = document.createElement('noscript'),
67
imageElement = document.createElement('img');
78

89
noscriptElement.classList.add('loading-lazy');
@@ -15,10 +16,11 @@ let addImage = (event) => {
1516

1617
noscriptElement.appendChild(imageElement);
1718

18-
document
19-
.querySelector('main')
20-
.insertAdjacentElement('beforeend', noscriptElement);
19+
divElement.appendChild(noscriptElement);
2120

21+
document.querySelector('main').insertAdjacentElement('beforeend', divElement);
22+
23+
// Call for preparing the sample image element included the latest
2224
loadingAttributePolyfill.prepareElement(
2325
document.querySelector('main noscript.loading-lazy')
2426
);

0 commit comments

Comments
 (0)