1073Javascript Images Sliders and Lightboxes

An evolving list of JS Image Sliders and Lightboxes.

Image Sliders

Slick - "the last carousel you'll ever need"

Swiper - "The Most Modern Mobile Touch Slider"

  • v11.1.12, September 1, 2024
  • 39.5k Github stars

Lightbox

Slick + Lightbox

  • Building upong Slick
  • no longer in development

Gallery/Slider AND Lightbox

PhotoSwipe

  • v5.4.4
  • 23.9k Github stars

TODO:

  • make examples and test

1008JS Loops and async/await

I've been trying to get data from an API, a async call is used to parse the data. I've be naively iterating over the responses with forEach, calling await in the forEach function, and wondering why it is not producing the result I expected, i.e. wait for the data to settle.

NG:

async function getData() {
  output = ""
  results.forEach(async (block) => {   
    var b = await abc.parse(block)
    output += b
  })
}

Solution

Use a standard for or for..of to loop over the list:

async function getData() {
  output = ""
  for (const block of results) {
    var b = await abc.parse(block)
    output += b
  }
}

996Playing/Pausing Embedded Vimeo Videos with custom JS

Embedded Vimeo in HTML Page:

<iframe id="vi" src="https://player.vimeo.com/video/123"></iframe>

Pause:

var msg = JSON.stringify({method: "pause"}

Play:

var msg = JSON.stringify({method: "play"}

jQuery:

$("#vi")[0].contentWindow.postMessage(msg, "*")

Pure JS:

document.getElementById("vi").contentWindow.postMessage(msg, "*")