Skip to content

Instantly share code, notes, and snippets.

@jessehintze
Created July 31, 2015 17:49
Show Gist options
  • Save jessehintze/01af2f937762515af090 to your computer and use it in GitHub Desktop.
Save jessehintze/01af2f937762515af090 to your computer and use it in GitHub Desktop.
bxslider with linked thumbnail slider
var sliders = {
realSlider : '',
realThumbSlider : '',
init : function(){
if($(window).width() <= 767){
sliders.startSliders();
}
sliders.windowResize();
},
startSliders : function(){
sliders.realSlider = $(".section-crumb-menu #bxslider").bxSlider({
pager:false,
controls: false,
infiniteLoop:false,
hideControlOnEnd:true,
adaptiveHeight: true,
swipeThreshold: 200,
speed: 350,
preventDefaultSwipeX: true,
touchEnabled: false,
onSlideBefore:function($slideElement, oldIndex, newIndex){
sliders.changeRealThumb(sliders.realThumbSlider,newIndex);
}
});
sliders.realThumbSlider = $(".section-crumb-menu #bxslider-pager").bxSlider({
minSlides: 2,
maxSlides: 7,
slideWidth: 146,
slideMargin: 10,
moveSlides: 2,
pager:false,
infiniteLoop:false,
hideControlOnEnd:true,
controls: false,
speed: 350,
onSlideBefore:function($slideElement, oldIndex, newIndex){
$("#bxslider-pager a.active").removeClass("active");
$slideElement.addClass("active");
sliders.changeRealThumb(sliders.realSlider,newIndex);
}
});
sliders.linkRealSliders(sliders.realSlider,sliders.realThumbSlider);
},
stopSliders : function(){
if(sliders.realSlider != '' && sliders.realThumbSlider != ''){
sliders.realSlider.destroySlider();
sliders.realThumbSlider.destroySlider();
sliders.realSlider = '';
sliders.realThumbSlider = '';
}
},
linkRealSliders: function(bigS, thumbS){
$(".section-crumb-menu #bxslider-pager").on("click","a",function(event){
event.preventDefault();
var newIndex=$(this).attr("data-slide-index");
bigS.goToSlide(newIndex);
});
},
changeRealThumb : function(slider,newIndex){
var $thumbS=$(".section-crumb-menu #bxslider-pager");
$thumbS.find('.active').removeClass("active");
$thumbS.find('[data-slide-index="'+newIndex+'"]').addClass("active");
if(slider.getSlideCount()-newIndex>=2)slider.goToSlide(newIndex);
else slider.goToSlide(slider.getSlideCount()-2);
},
windowResize : function(){
$(window).resize(function() {
clearTimeout(window.resizedFinished);
window.resizedFinished = setTimeout(function(){
var wwindow = $(window).width();
if (wwindow >= 768){
sliders.stopSliders();
}
else if(wwindow <= 767 ){
if(sliders.realSlider == '' && sliders.realThumbSlider == ''){
sliders.startSliders();
}
}
}, 100);
});
}
};
if($('body').hasClass('section-crumb-menu')){
sliders.init();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment