julienmonnerie/assets/js/app.js

53 lines
1.7 KiB
JavaScript
Raw Normal View History

2022-08-02 18:50:27 +02:00
import Splide from '@splidejs/splide';
import create from 'swiped-events';
2022-08-02 18:50:27 +02:00
2022-06-17 17:51:59 +02:00
// ----------------------------------------------------------------------------
// DATA
// ----------------------------------------------------------------------------
2025-05-23 17:17:38 +02:00
// const body = document.body;
const homeCarousels = document.querySelectorAll('.home__carousel');
2022-06-17 17:51:59 +02:00
// ----------------------------------------------------------------------------
2022-07-28 18:59:14 +02:00
// LOGIC
2022-06-17 17:51:59 +02:00
// ----------------------------------------------------------------------------
// Convert rem to pixels by getting font-size CSS property
2025-05-23 17:17:38 +02:00
// function convertRemToPixels(rem) {
// let fontSize = parseFloat(window.getComputedStyle(body).getPropertyValue('font-size'));
// return rem * fontSize;
// }
// Set up multiple Splide carousels
function setUpCarousels() {
if (homeCarousels.length) {
homeCarousels.forEach((item) => {
// Create Splide instance
let slider = new Splide(item, {
arrows: false,
drag: true,
easing: 'ease-in-out',
pagination: false,
rewind: true,
rewindByDrag: true,
role: 'undefined',
2025-05-25 18:29:02 +02:00
speed: 0,
2025-05-23 17:17:38 +02:00
type: 'fade',
width: 'auto',
});
// Mount slider
slider.mount();
// Change slide on click
slider.on('click', () => {
2022-11-23 14:55:44 +01:00
slider.go('>');
2025-05-23 17:17:38 +02:00
});
});
2022-09-09 15:26:04 +02:00
}
}
2022-06-17 17:51:59 +02:00
// ----------------------------------------------------------------------------
// PROGRAM
// ----------------------------------------------------------------------------
2025-05-23 17:17:38 +02:00
setUpCarousels();