通过layui轮播图展示ajax动态数据的问题


<div class="layui-carousel" id="carouselView">
    <div carousel-item="" id="preview">

    </div>
</div>
function initCarousel(){
layui.use(['carousel', 'form'], function(){
var carousel = layui.carousel;
$.ajax({
url:'GetCarouselServlet',
type:'post',
data:{
isDisplay:1
},
dataType:'json',
success:function (data) {
$.each(data,function (i,n) {
var str = '<div>\n' +
' <img src="../upload/'+n.picUrl+'" alt="" style="width: 600px;height: 320px;">\n' +
' </div>';
$('#preview').append(str);

});
//改变下时间间隔、动画类型、高度
var ins = carousel.render({
elem: '#carouselView'
,interval: 2000
,arrow: 'always'
,anim: 'default'
,width:'600px'
,height:'320px'
});
ins.reload({
elem: '#carouselView'
,interval: 2000
,arrow: 'always'
,anim: 'default'
,width:'600px'
,height:'320px'
});
},
error:function () {
alert("数据库查询失败,请联系管理员!")
}
});
});
}

initCarousel();

网上找了半天解决方法,也没搞明白,我想起layui框架在form表单渲染的时候在ajax里写过form.render('form')这样的代码

就想到把layui轮播图设置,放在加载数据后,在设置轮播图的属性,另外一定要加 ins.reload()这个方法,这个是重置轮播图用的!!


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM