|
function initSwipe(){//从后台获取首页的图片,并轮播
Glm.utils.getAjaxData("/seller/navigate", {
"type":Math.round(2)
}, function(data){
if(data.status == 200){
var img = data.response;//多个obj
var imgArr=[];
var urlArr=[];
$.each(img,function(i){//遍历每个obj,获取image
var objIndex=img[i];
this.image = Glm.utils.setImgUrl(objIndex.image);
imgArr.push(this.image);
if(objIndex.url=="")
urlArr.push("javascript:void(0);");
else
urlArr.push(objIndex.url);
});
$.each(imgArr,function(i){//遍历imgUrlArr数组,动态添加html
$('.swiper-wrapper').append($(
'<div class="swiper-slide" >' +
'<a href="'+urlArr[i]+'"><img src="'+imgArr[i]+'"></a>'+
'</div>'
));
});
new Swiper(".advertise", {
direction: "horizontal",
autoplay: 2000,
autoplayDisableOnInteraction: false,
loop: true,
pagination: '.swiper-pagination'
});
}else{
alert("失败!");
}
}, function(){
alert("获取图片失败!");
});
}
|
|