Created
November 28, 2016 17:21
-
-
Save timaschew/25cb2d3f9c08ae134c0b6ea78a15256b to your computer and use it in GitHub Desktop.
hallo-piepmatz gif-show
This file contains hidden or 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
<script> | |
var getAttr = function(element, attr) { | |
return element.attributes[attr].value; | |
}; | |
var hideAll = function(parent) { | |
for (var i=0; i<parent.children.length; i++) { | |
var child = parent.children[i]; | |
child.style.display = 'none'; | |
} | |
}; | |
var show = function(element) { | |
element.style.display = 'inherit'; | |
}; | |
var createGifShow = function(parent) { | |
var speed = parseInt(getAttr(parent, 'data-speed')); | |
if (isNaN(speed)) speed = 500; | |
var children = parent.children; | |
var index = 0; | |
setInterval(function() { | |
hideAll(parent); | |
if (index >= children.length) { | |
index = 0; | |
} | |
var child = children[index++]; | |
while (child.nodeName === 'BR') { | |
child = children[index++]; | |
} | |
show(child); | |
}, speed); | |
}; | |
var imgContainer = document.querySelectorAll(".gif-show"); | |
for (var i=0; i<imgContainer.length; i++) { | |
createGifShow(imgContainer[i]); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment