我在 swiper的父级上加了display:none后,swiper不能正常加载。
var swiper = new Swiper('.swiper-container', {
slidesPerView: 2.5,
freeMode: true,
spaceBetween: 8,
scrollbar: '.swiper-scrollbar',
observer: true,//修改swiper自己或子元素时,自动初始化swiper
observeParents: true//修改swiper的父元素时,自动初始化swiper
});
只需加上后两行内容即可:
observer: true,//修改swiper自己或子元素时,自动初始化swiper
observeParents: true//修改swiper的父元素时,自动初始化swiper