javascript - idangero.us swiper update tabs on slide swipe -
building mobile mobile app demo using idangero.us swiper:
http://www.idangero.us/sliders/swiper/
i've almost got working way want, 1 issue:
when click on 1 of tabs in menu, changes it's class "active" , slides proper slide. need change tab class when user manually swipes 1 of slides. if swipe "about us" slide example, corresponding tab should change active.
there's example of in action here:
i can't figure out how make work when have 2 swipers on page (one nav, , 1 body).
here's js:
$(function(){ //init navigation var nav = $('.swiper-nav').swiper({ slidesperview: 'auto', freemode:true, freemodefluid:true, onslideclick: function(nav){ pages.swipeto( nav.clickedslideindex ) } }) $(".swiper-nav a").on('touchstart mousedown',function(e){ e.preventdefault() $(".swiper-nav .active").removeclass('active') $(this).addclass('active') tabsswiper.swipeto( $(this).index() ) }) $(".swiper-nav a").click(function(e){ e.preventdefault() }) //init pages var pages = $('.swiper-pages').swiper() })
thanks.
try use onslidechangeend callback swiper api.
//init pages var pages = $('.swiper-pages').swiper({ onslidechangeend: function(swiper, direction) { $(".swiper-nav .active").removeclass('active'); $(".swiper-nav li:nth-child("+(swiper.activeindex+1)+") a").addclass('active'); } });
Comments
Post a Comment