var honorSwiper; var col; var ind; $(document).ready(function(){ var _len = $(".honor_r .honor_list").length; console.log("honor_r_wrap: "+$(".honor_r_wrap").length) if($(window).width()<768){ col = 2; }else{ col = 8; } for(var i=0;i<_len;i=i+col){ var $slide = $('
'); for(var j=i;j') $pad.append($(".honor_r .honor_list").eq(j).html()); $slide.append($pad); } $(".honor_r .swiper-wrapper").append($slide); } $(".honor_r .honor_list").remove(); honorSwiper = new Swiper('.honor_r .swiper-container', { prevButton:'.honor_r .swiper-button-prev', nextButton:'.honor_r .swiper-button-next', }) $(".honor_r_wrap").click(function(){ $(".honor_r").find(".honor_r_wrap").removeClass("on"); $(this).addClass("on"); var src = $(this).find("img").attr("src"); var info = $(this).find("img").data("info"); ind = $(this).data("ind"); btn() console.log(ind) $(".honor_l_img_wrap img").attr("src",src); $(".honor_l_info").html(info); }) $(".honor_l_btn").click(function(){ if($(this).hasClass("honor_l_l")){ ind--; if(ind < 0){ ind = 0; } if(ind % col == col-1){ try{ honorSwiper.slideTo(ind / col); }catch(e){ //TODO handle the exception } } }else{ ind++; if(ind > _len-1){ ind = _len-1; } if(ind % col == 0){ try{ honorSwiper.slideTo(ind / col); }catch(e){ //TODO handle the exception } } } btn(); $(".honor_l_img_wrap img").attr("src",$(".honor_r_wrap").eq(ind).find("img").attr("src")); $(".honor_l_info").html($(".honor_r_wrap").eq(ind).find("img").data("info")); $(".honor_r").find(".honor_r_wrap").removeClass("on"); $(".honor_r_wrap").eq(ind).addClass("on"); console.log(ind) }) $(".honor_r .swiper-slide:eq(0) .honor_pad:eq(0) .honor_r_wrap").click() function btn(){ if(ind == 0){ $(".honor_l_l").addClass("disabled"); $(".honor_l_r").removeClass("disabled") }else if(ind == _len-1){ $(".honor_l_r").addClass("disabled"); $(".honor_l_l").removeClass("disabled") }else{ $(".honor_l_l,.honor_l_r").removeClass("disabled") } } })