Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy Loaded Images #641

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

crolla97
Copy link

@crolla97 crolla97 commented Jan 3, 2023

Hey @jedrzejchalubek I've added lazy image loading as requested by #362

I've kept it pretty barebones in functionality as I wait to see if this is:

  1. Something you even want the project to have.
  2. How big in scope the lazy loading feature should be.

Initalization

The HTML syntax for lazy loading images is as follows:

<div class="glide">
  <div class="glide__track" data-glide-el="track">
    <ul class="glide__slides">
      <li class="glide__slide"><img class='glide__lazy' data-src="IMAGE_URL"></li>
      <li class="glide__slide"><img class='glide__lazy' data-src="IMAGE_URL"></li>
      <li class="glide__slide"><img class='glide__lazy' data-src="IMAGE_URL"></li>
    </ul>
  </div>
</div>

To initialize lazy loading the default lazy must be set to true, by default it is false.

new Glide('#glide', { lazy: true }).mount()


Additional defaults

  • lazyInitialSlidesLoaded
    Defines the initial amount of slides to be loaded

  • lazyScrollThreshold
    Defines the threshold in which lazy loading will begin. For example, a threshold of 1.2 will load the images if the carousel/slider is within 120% of the screen width and height

Let me know what you think, happy to amend PR further if necessary.

@crolla97 crolla97 mentioned this pull request Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant