Created
January 5, 2016 17:14
-
-
Save Caaz/edb55926ea1c453ddf1c to your computer and use it in GitHub Desktop.
Slider fix
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
var sliderIndex = 0; | |
var refreshIntervalId; | |
var $images = $(".slide-group").children(); | |
$(function(){ | |
var $bar = $('.slide-buttons'); | |
addButton("Previous", prev, $bar); | |
addButton("Next", next, $bar); | |
}) | |
function next(){ | |
sliderIndex = (sliderIndex<$images.length-1)?sliderIndex+1:0; | |
slide(); | |
} | |
function prev(){ | |
sliderIndex = (sliderIndex<0)?sliderIndex-1:$images.length-1; | |
slide(); | |
} | |
function slide(){ | |
$images.fadeOut(); | |
$($images[sliderIndex]).slideDown(); | |
} | |
function validate() { | |
if (document.getElementById('remember').checked) { | |
refreshIntervalId = window.setInterval(next, 1000); | |
} else { | |
window.clearInterval(refreshIntervalId) | |
refreshIntervalId = null; | |
} | |
} | |
function addButton(name, click, $element){ | |
var $button = $("<button>"); | |
$button.text(name); | |
$button.on('click', click); | |
$element.append($button); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment