Created
October 12, 2015 14:59
-
-
Save jacopotarantino/b1d568404aa9e44cf791 to your computer and use it in GitHub Desktop.
Twerkify - Make your website twerk.
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
(function () { | |
'use strict' | |
/** | |
* @module Twerkify | |
* @description Thank you for twerking. Use at your own risk. | |
*/ | |
console.log('Thank you for twerking') | |
var json_request | |
json_request = new window.XMLHttpRequest() | |
json_request.addEventListener('load', parse_json) | |
json_request.open('GET', 'https://api.giphy.com/v1/gifs/search?q=twerking&api_key=dc6zaTOxFJmzC') | |
json_request.send() | |
function parse_json () { | |
var gifs, dom_images, node_array | |
gifs = JSON.parse(this.responseText) | |
dom_images = document.querySelectorAll('img') | |
node_array = Array.prototype.slice.call(dom_images) | |
node_array.forEach(function (node, index, array) { | |
var gif = gifs.data[ Math.floor(Math.random() * gifs.data.length) ] | |
node.src = gif.images.fixed_height.url | |
}) | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment