如果您不仅想要延迟加载,还想要预加载以下幻灯片,您应该将解决方案从 Brownrice 更改为
$(window).load(function() {
$('#sld-auto-930').flexslider({
// put your settings properties here
start: function (slider) {
// preloading the second slide on initialization
var slides = slider.slides,
$slide = $(slides[1]),
$img = $slide.find('img[data-src]');
if($img){
$img.attr("src", $img.attr('data-src')).removeAttr("data-src");
}
},
after: function (slider) {
//instead of going over every single slide, we will just load the next immediate slide
var slides = slider.slides,
index = slider.animatingTo+1,
$slide = $(slides[index]),
$img = $slide.find('img[data-src]');
if($img){
$img.attr("src", $img.attr('data-src')).removeAttr("data-src");
}
}
});
});
使用此代码,第二张幻灯片将在页面加载期间预加载,并且在前一张幻灯片处于活动状态时将预加载每张下一张幻灯片。