swiper保存

//初始化swiper
var index=0;
if(sessionStorage.getItem("index")){
index=sessionStorage.getItem("index");
}
var swiper = new Swiper('.swiper-container', {
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev',
initialSlide: index,//设定初始化时slide的索引
centeredSlides: true
});
//点击页面链接跳转前保存导航当前的index值
$("a").bind("click",function(){
var i= $(".swiper-slide-active").index();
sessionStorage.setItem("index",i);
})

posted @ 2017-08-14 14:41  幻城love  阅读(189)  评论(0编辑  收藏  举报