Created
January 22, 2014 19:54
-
-
Save aaronfischer/8566148 to your computer and use it in GitHub Desktop.
iOS Slider basic setup + helper functions
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
// Slider build pagination before iosslider loads | |
$('.general .slides').each(function(i,e){ | |
if($(this).find('> .slide').length > 1){ | |
slidePaginate(i,e); | |
} | |
}); | |
// this should be run outside of the iosslider load code | |
function slidePaginate(i,e,el) { | |
var e = $(e); | |
console.log(e); | |
if(e.parent().find('.ios-control-nav').length){ | |
// do nothing | |
} else{ | |
var itemCount = e.find('li').length - 1, | |
items = [], | |
paginate = "<ol class='ios-control-nav'></ol>"; | |
for (var i = 0; i <= itemCount; i++) { | |
items += '<li><a>'+i+'</a></li>'; | |
} | |
e.parent().append(paginate); | |
e.parent().find('.ios-control-nav').append(items).find("li:first-child").addClass("ios-active"); | |
} | |
} | |
$('.general .slides').each(function(){ | |
if($(this).find('> .slide').length > 1){ | |
$(this).closest('.iosslider-resize').iosSlider({ | |
navSlideSelector: $('.ios-control-nav > li:not(.ios-prev,.ios-next)'), | |
navPrevSelector: '.ios-direction-nav > .ios-prev', | |
navNextSelector: '.ios-direction-nav > .ios-next', | |
snapToChildren: true, | |
desktopClickDrag: true, | |
sliderCSS: { | |
overflow: 'visible', | |
}, | |
onSlideChange: slideChange, | |
onSliderResize: sliderResize, | |
onSliderLoaded: slidePaginateResize | |
}); | |
} | |
}); | |
function slideChange(args) { | |
args.sliderContainerObject.parent().find('.ios-control-nav, .control-nav').find('li:not(.ios-prev,.ios-next)').removeClass("ios-active"); | |
args.sliderContainerObject.parent().find('.ios-control-nav, .control-nav').find('li:not(.ios-prev,.ios-next):eq(' + (args.currentSlideNumber - 1) + ')').addClass("ios-active"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment