Created
March 11, 2016 16:09
-
-
Save BobbyAdamson/34c5ece1846c034d1e58 to your computer and use it in GitHub Desktop.
Flip a random media item that's on the page
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
randomFlipping = function(){ | |
// So we know what to flip | |
var mediaItem = $('.xItem.xMedialayer.xContentImage, .xItem.xMedialayer.xContentVideo'); | |
// So we know how many items there are | |
var totalItemsWithMedia = $(mediaItem).length; | |
// Want to run the function on a somewhat random interval | |
setInterval(function(){ | |
// Randomly finding an element to flip | |
var itemNumberToFlip = Math.round(Math.random() * totalItemsWithMedia); | |
var itemToFlip = $(mediaItem)[itemNumberToFlip]; | |
// Flip the element | |
$(itemToFlip).find('.xItemInner').addClass('xActive'); | |
// Flip the element back in a few seconds | |
setTimeout(function(){ | |
$(itemToFlip).find('.xItemInner').removeClass('xActive'); | |
}, (Math.random() * 6) + 6 * 1000); | |
}, ((Math.random() * 6)) * 500); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment