页面渲染完再写轮播图插件,好多插件都是这样
$.ajax({
type: "GET",
url: "/banner/list",
success: function (res) {
console.log("轮播图", res);
if (res.code == 0) {
for (var i = 0; i < res.data.length; i++) {
$('.swiper-wrapper').append($('<div class="swiper-slide"><img src="' + res.data[i].banner_path + '"/></div>'))
};
var mySwiper = new Swiper('.swiper-container', {
direction: 'horizontal', // 水平切换选项
slidesPerView: 1.1,
spaceBetween: -30,
centeredSlides: true,
loop: true, // 循环模式选项
autoplay: {
delay: 3000,//3秒切换一次
},
// 如果需要分页器
pagination: {
el: '.swiper-pagination',
},
});
} else if (res.code == 2) {
location.href = "login.html"
} else {
$("#error_info").text(res.msg);
$("#error_info").show().delay(500).hide(100);
}
},
error: function (fal) {
if (fal.responseJSON.status == 600) {
location.href = "hdyp_cold.html"
} else if (fal.responseJSON.status == 601) {
$("#error_info").text("您的账号在其他设备上登录,请重新登录!");
$("#error_info").show().delay(500).hide(100);
setTimeout('location.href="login.html"', 1000);
}
}
});