Skip to content

Instantly share code, notes, and snippets.

@colxi
Created July 1, 2019 18:50
Show Gist options
  • Save colxi/dc2270b40a048c0b1e85a5349eb50fec to your computer and use it in GitHub Desktop.
Save colxi/dc2270b40a048c0b1e85a5349eb50fec to your computer and use it in GitHub Desktop.
Random Masonry element slideshow
var results = Array.from( document.querySelectorAll('.masonry_box.small_pin_box > .image_wrapper') );
var div = document.createElement('div');
div.style =`
position: fixed;
width:100%;
height: 100%;
background:black;
top :0px;
left :0px;
display: grid;
` ;
document.body.appendChild( div );
var img = document.createElement('img');
img.style = `
height: 100%;
align-self: center;
margin:auto;
`;
img.onclick = function(){
var item = Math.random( new Date() ) * results.length << 0 ;
var selectedImage = results[ item ].querySelector('.image').dataset.src;
img.src = selectedImage;
};
div.appendChild( img );
var item = Math.random( new Date() ) * results.length << 0 ;
var selectedImage = results[ item ].querySelector('.image').dataset.src;
img.src = selectedImage;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment