码迷,mamicode.com
首页 > Web开发 > 详细

ajax请求图片添加到swiper

时间:2018-04-20 10:17:56      阅读:1409      评论:0      收藏:0      [点我收藏+]

标签:play   date   UNC   delay   .ajax   ++   class   使用   ESS   

使用swiper制作轮播图的时候,轮播的图片大概率是使用ajax从后台获取到的。每一次获取图片都要重新初始化swiper.


$.ajax({
type: "get",
url: "update/",
dataType: "json",
success: function(data) {
data = JSON.parse(data);
console.log(data);
for(var i = 0; i < data.length; i++) {
$(‘.banner .swiper-wrapper‘).append($(‘<div class="swiper-slide"><img src=‘ + data.path + ‘/></div>‘))
};
var swiper = new Swiper(‘.swiper-container‘, {
loop: true,
centeredSlides: true,
autoplay: {
delay: 2500,
},
pagination: {
el: ‘.swiper-pagination‘,
clickable: true,
},

});
},
error: function() {

}
});

ajax请求图片添加到swiper

标签:play   date   UNC   delay   .ajax   ++   class   使用   ESS   

原文地址:https://www.cnblogs.com/yinhuiyang/p/8888239.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!