Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aaronfischer/8566148 to your computer and use it in GitHub Desktop.
Save aaronfischer/8566148 to your computer and use it in GitHub Desktop.
iOS Slider basic setup + helper functions
// 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