From 438d3c40ae9d8ad65a314255e94da9662181cbfe Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 29 Jun 2015 02:37:05 +0200 Subject: [PATCH] Add lazyDistance option to prefetch 1 prev/next slide by default --- jquery.fullPage.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/jquery.fullPage.js b/jquery.fullPage.js index 17186e0ab..57479825c 100755 --- a/jquery.fullPage.js +++ b/jquery.fullPage.js @@ -103,6 +103,7 @@ slidesNavigation: false, slidesNavPosition: 'bottom', scrollBar: false, + lazyDistance: 1, //scrolling css3: true, @@ -1348,6 +1349,25 @@ var slide = destiny.find(SLIDE_ACTIVE_SEL); if( slide.length ) { destiny = $(slide); + + if( destiny.length == 1 && destiny.filter(SLIDE_SEL).length ) { + // Handling a single slide. + if( options.lazyDistance ) { + var prev = destiny.prevAll(':lt('+options.lazyDistance+')'); + var next = destiny.nextAll(':lt('+options.lazyDistance+')'); + + // Add first/last sibling when there's no next/prev. + // (does not use options.lazyDistance currently). + if (options.loopHorizontal ) { + if(!next.length) { + next = destiny.siblings(':first'); + } else if(!prev.length) { + prev = destiny.siblings(':last'); + } + } + destiny = destiny.add(prev).add(next); + } + } destiny.find('img[data-src], video[data-src], audio[data-src]').each(function(){ $(this).attr('src', $(this).data('src'));