The issue seems to be with how Safari handles the pause method on videos. To address this, I added a check to ensure the video element is fully loaded before applying the play and pause functionality.
Here’s the updated code:
document.querySelectorAll(‘.image-stack-video-elem video’).forEach(video => {
// Ensure the video is fully loaded before attaching event listeners
video.addEventListener(‘loadeddata’, () => {
// Play video on hover
video.parentElement.addEventListener(‘mouseenter’, () => {
video.play();
});
// Pause video on mouse leave
video.parentElement.addEventListener('mouseleave', () => {
video.pause();
});