Created
September 17, 2014 22:03
-
-
Save ajschlosser/37e7e159840e88171fd0 to your computer and use it in GitHub Desktop.
A quick fix for fading slides. Will cycle through <div> elements with the class "ds-slide" and apply the class "ds-faded" to them at predefined intervals. The "ds-faded" class can then by styled with transitions of your choice.
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
// Slides | |
var divSlider = function () { | |
var ds = this; | |
var transitionClass = "ds-faded"; | |
ds.n = 0; | |
ds.pause = function () { clearInterval(ds._intervalId); } | |
ds.toggle = function () { | |
console.log(ds.n, ds.slides.length-1); | |
ds.n < ds.slides.length-1 ? ds.n++ : ds.n = 0; | |
var prev = ds.n; | |
var s = ds.slides; | |
var i = s.length; | |
while (i--) { | |
var slide = s[i]; | |
var children = slide.childNodes; | |
if (i != prev) { | |
slide.classList.add(transitionClass); | |
var j = children.length; | |
while (j--) children[j].style.pointerEvents = "none"; | |
} | |
else { | |
slide.classList.remove(transitionClass); | |
var j = children.length; | |
while (j--) children[j].style.pointerEvents = "auto"; | |
} | |
} | |
} | |
ds.init = function () { | |
ds.slides = document.getElementsByClassName("ds-slide"); | |
for (var i = 0; i < ds.slides.length; i++) { | |
if (i > 0) ds.slides[i].classList.add(transitionClass); | |
} | |
ds._intervalId = setInterval(ds.toggle, 10000); | |
} | |
ds.init(); | |
}; | |
var ds = new divSlider(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment