Skip to content

Instantly share code, notes, and snippets.

@Flowbaseco
Last active January 15, 2023 13:42
Show Gist options
  • Save Flowbaseco/238a7ee80c049fd832f087f8fcbc460b to your computer and use it in GitHub Desktop.
Save Flowbaseco/238a7ee80c049fd832f087f8fcbc460b to your computer and use it in GitHub Desktop.
<script src="https://unpkg.com/beerslider/dist/BeerSlider.js"></script>
<script>
// Wait for the page to load
$(document).ready(function () {
// Select all elements with the class "image-wrapper" and loop through them
const imageWrappers = document.getElementsByClassName("image-wrapper");
for(const imageWrapper of imageWrappers){
// Get the source of the first and second image within the current "image-wrapper" element
const firstImage = imageWrapper.querySelectorAll('img')[0].src;
const secondImage = imageWrapper.querySelectorAll('img')[1].src;
// Create a template for the beer slider using the first and second image sources
const template = `
<div class="beer-slider" data-beer-label="before">
<img src="${firstImage}">
<div class="beer-reveal" data-beer-label="after">
<img src="${secondImage}">
</div>
</div>
`;
// Remove the first and second images
imageWrapper.querySelectorAll('img')[1].remove();
imageWrapper.querySelectorAll('img')[0].remove();
// Append the template to the current "image-wrapper" element
imageWrapper.insertAdjacentHTML('afterbegin',template);
}
// Select all elements with the class "beer-slider" and loop through them
const beerSliders = document.getElementsByClassName("beer-slider");
for(const beerSlider of beerSliders){
// Initialize the BeerSlider plugin on the current element, passing in the "start" data attribute as the option
new BeerSlider(beerSlider, { start: beerSlider.dataset.start });
}
});
</script>
<style>
.beer-slider {
height: 100% !important;
}
.beer-slider,
.beer-slider>img {
width: 100% !important;
}
.beer-range::-webkit-slider-thumb {
-webkit-appearance: auto;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment