swiper动态渲染数据

页面渲染完再写轮播图插件,好多插件都是这样

$.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);
		}
	}
});
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值