Skip to content

Instantly share code, notes, and snippets.

@a-barbieri
Last active November 11, 2019 14:28
Show Gist options
  • Save a-barbieri/8f96aa7cff41e6bf7fcda6a281693bdc to your computer and use it in GitHub Desktop.
Save a-barbieri/8f96aa7cff41e6bf7fcda6a281693bdc to your computer and use it in GitHub Desktop.
Per Pyetro
<?php if (have_posts()): ?>
<ul id="image-data-list">
<?php while(have_posts()): the_post(); ?>
<li data-image-url="<?= your_post_image_url ?>"></li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
document.addEventListener( 'DOMContentLoaded', function( event ) {
const imagesData = document.querySelectorAll('#image-data-list > li');
const imagesUrlList = [];
[...imagesData].forEach(image => {
const url = image.getAttribute("data-image-url");
if (url) {
imagesUrlList.push(url);
}
});
imagesUrlList.each(imageUrl => {
// load the imageUrl
});
});
$(document).ready(function() {
var imagesUrlList = [];
$("#image-list > li").each(function() {
var url = $(this).data("image-url");
if (url !== "" && url !== null) {
imagesUrlList.push(url);
}
});
imagesUrlList.each(imageUrl => {
// load the imageUrl
});
});
@a-barbieri
Copy link
Author

Hey @subfighter3 this is for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment