Skip to content

Instantly share code, notes, and snippets.

@BobbyAdamson
Created March 11, 2016 16:09
Show Gist options
  • Select an option

  • Save BobbyAdamson/34c5ece1846c034d1e58 to your computer and use it in GitHub Desktop.

Select an option

Save BobbyAdamson/34c5ece1846c034d1e58 to your computer and use it in GitHub Desktop.

Revisions

  1. Bobby Adamson created this gist Mar 11, 2016.
    23 changes: 23 additions & 0 deletions randomFlipping.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    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);
    },