Skip to content

Instantly share code, notes, and snippets.

@timaschew
Created November 28, 2016 17:21
Show Gist options
  • Save timaschew/25cb2d3f9c08ae134c0b6ea78a15256b to your computer and use it in GitHub Desktop.
Save timaschew/25cb2d3f9c08ae134c0b6ea78a15256b to your computer and use it in GitHub Desktop.
hallo-piepmatz gif-show
<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