Slick: On demand lazy load not working with initialSlide and slidesToScroll

Created on 29 Feb 2016  路  7Comments  路  Source: kenwheeler/slick

Lazy loading of type 'ondemand' fails to load some visible slides in certain situations

http://jsfiddle.net/abwb1aby/2/

Steps to reproduce the problem

  1. Create a slick with a number of slides that is greater than its slidesToScroll, but not a multiple of slidesToScroll.
  2. Include images on each slide with a data-lazy attribute.
  3. Set infinite and centerMode to false, set lazyLoad to 'ondemand'
  4. Set the initial slide to a slide on the last page of scrolling (e.g. n-1)

What is the expected behaviour?

All visible slides should be lazy loaded when the slick initializes

What is observed behaviour?

There are visible slides to the left of the "currentSlide" that do not get lazy loaded during init

More Details

  • Which browsers/versions does it happen on? All
  • Which jQuery/Slick version are you using? N/A
  • Did this work before? No
Confirmed Lazyload

Most helpful comment

2255

All 7 comments

The fix is to use rangeStart = _.currentSlide - Math.max(0, _.currentSlide + _.options.slidesToShow - _.slideCount); when infinite and centerMode are false. I'll submit a PR when I get a chance.

This sounds related to #2110, which I made a PR for here #2164, but when I tested the PR against your fiddle, I found a bug with scrolling--cant get to slide 1. Thanks for the issue @rphelan. I look forward to your PR.

@rphelan @leggomuhgreggo Was there ever a PR sent in for this? Having the same issue

@rphelan I've been trying to figure this bug out for a little bit now. For some reason converting the lazyLoad function to use Jquery made it work everytime for me, as well as Implenting an additional conditional to handle the infinite option at a higher level.

Also not sure if this makes any sense but before I changed the function over to jquery I was able to get the original way to work by adding a console.log directly after the img tag creation. Is there some sort of race case at play here and delaying the function a little more caused it to work? Seems pretty bizarre to me.

@mcclaskiem Sorry, I forgot about this one, working on a PR now. I do not expect it to fix the scrolling issue that @leggomuhgreggo mentioned though as I think its separate (although caused by the same combination of settings).

2255

Any updates on this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stephane-r picture stephane-r  路  3Comments

REPTILEHAUS picture REPTILEHAUS  路  3Comments

Libig picture Libig  路  3Comments

yangkennyk picture yangkennyk  路  3Comments

k-lusine picture k-lusine  路  3Comments