Created
July 1, 2019 18:50
-
-
Save colxi/dc2270b40a048c0b1e85a5349eb50fec to your computer and use it in GitHub Desktop.
Random Masonry element slideshow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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