在加载动态内容时尝试续订nivoslider时遇到了一些问题。我需要做的是在通过AJAX
调用加载新内容时更新滑块。
所以基本上我有一个div从函数AJAX
调用中获取新数据,在加载后我需要滑块重新初始化。
我现在做的是:
if ($('#imageSlider').find('div.nivo-slice').length > 0) {
$('#imageSlider').data('nivoslider').stop();
$('#imageSlider').removeData('nivo:vars');
$('#imageSlider').removeData('nivoslider');
$('#imageSlider').attr("class","");
$('#imageSlider').attr("style","");
}
$('#imageSlider').html(newImages);
然后拨打$('#imageSlider').nivoSlider();
它有点工作,但旋转仅停留在一张图片上,有时它只是没有加载。对此的任何帮助将不胜感激。
答案 0 :(得分:2)
我找到了解决方案。而不是只替换我内部的图像替换html里面。所以喜欢制作新的nivoslider内容,它对我有用。然后使用所有参数再次启动nivoslider
ajax响应后 -
j('.slider-wrapper').html('');
j('.slider-wrapper').html(request);
j('#slider').nivoSlider({
effect: 'fade', // Specify sets like: 'fold,fade,sliceDown'
slices: 15, // For slice animations
boxCols: 8, // For box animations
boxRows: 4, // For box animations
animSpeed: 5, // Slide transition speed
pauseTime: 3000, // How long each slide will show
startSlide: 0, // Set starting Slide (0 index)
directionNav: true, // Next & Prev navigation
directionNavHide: true, // Only show on hover
controlNav: false, // 1,2,3... navigation
controlNavThumbs: false, // Use thumbnails for Control Nav
controlNavThumbsFromRel: false, // Use image rel for thumbs
controlNavThumbsSearch: '.jpg', // Replace this with...
controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
keyboardNav: true, // Use left & right arrows
pauseOnHover: true, // Stop animation while hovering
manualAdvance: false, // Force manual transitions
captionOpacity: 0.8, // Universal caption opacity
prevText: 'Prev', // Prev directionNav text
nextText: 'Next', // Next directionNav text
beforeChange: function(){}, // Triggers before a slide transition
afterChange: function(){}, // Triggers after a slide transition
slideshowEnd: function(){}, // Triggers after all slides have been shown
lastSlide: function(){}, // Triggers when last slide is shown
afterLoad: function(){} // Triggers when slider has loaded
});