jcarousellite_1.0.1c4.js是一个常用的插件,其实官网说的很清楚了。
但是我在使用的时候,发现如果频繁调用获取数据接口,滚动就有问题了。
问题:滚动的速度特别快 ,我的代码贴出来了,没问题吧!!!
$.ajax({ url:url,
type:'get',
dataType: 'json',
success:function(data){
if(data.code==0){
$('.content-name-li ul li').length>0 && (function(){
$(".content-name-li").jCarouselLite({
vertical: true,
hoverPause:true,
visible: 1,
auto:1000,
speed:1000
})
})();
},
error:function(data){
unlock('获取失败!');
}
});
看看源码吧,肯定是定时器控制的伐,频繁调用接口,打乱了定时器。所以我们要给一个状态。不要让定时器傻傻分不清楚。
var timeStatus = true;
$.ajax({ url:url,
type:'get',
dataType: 'json',
success:function(data){
if(data.code==0){
if(timeStatus){
$('.content-name-li ul li').length>0 && (function(){
$(".content-name-li").jCarouselLite({
vertical: true,
hoverPause:true,
visible: 1,
auto:1000,
speed:1000
})
})();
}
},
error:function(data){
unlock('获取失败!');
}
});
其他地方调用接口的时候,设置timeStatus = false
![](https://img.haomeiwen.com/i12427014/b6130839f08c7b9d.jpeg)
网友评论