single product visiblity? version

This commit is contained in:
nomadics9 2025-04-03 17:52:05 +03:00
parent 15400e93d6
commit 598040832e

View file

@ -24,76 +24,83 @@
// });
//});
//
jQuery(document).ready(function($) {
if (window.location.pathname.startsWith('/product/')) return;
//
//
//
$('.product-slider-container').each(function() {
const container = $(this);
const slider = container.find('.product-image-slider');
const items = slider.find('.slider-item');
let currentIndex = 0;
// Hide all except first
items.css({ position: 'absolute', opacity: 0, transition: 'opacity 0.3s ease' });
items.eq(currentIndex).css({ opacity: 1, position: 'relative' });
// Create and insert dots
if (items.length <= 1) return;
const dotsContainer = $('<div class="slider-dots"></div>');
items.each(function(i) {
const dot = $('<span class="slider-dot"></span>');
if (i === 0) dot.addClass('active');
dot.on('click', function() {
currentIndex = i;
updateSlide();
});
dotsContainer.append(dot);
});
container.append(dotsContainer);
// Slide update function
function updateSlide() {
items.css({ opacity: 0, position: 'absolute' });
items.eq(currentIndex).css({ opacity: 1, position: 'relative' });
dotsContainer.find('.slider-dot').removeClass('active')
.eq(currentIndex).addClass('active');
}
// Touch swipe
let touchStartX = 0;
let touchEndX = 0;
slider.on('touchstart', function(e) {
touchStartX = e.originalEvent.touches[0].clientX;
});
slider.on('touchend', function(e) {
touchEndX = e.originalEvent.changedTouches[0].clientX;
const delta = touchEndX - touchStartX;
if (Math.abs(delta) > 50) {
if (delta < 0) {
currentIndex = (currentIndex + 1) % items.length;
} else {
currentIndex = (currentIndex - 1 + items.length) % items.length;
}
updateSlide();
}
});
// Optional: support prev/next buttons too
container.find('.slider-prev').on('click', function() {
currentIndex = (currentIndex - 1 + items.length) % items.length;
updateSlide();
});
container.find('.slider-next').on('click', function() {
currentIndex = (currentIndex + 1) % items.length;
updateSlide();
});
});
});
//
//jQuery(document).ready(function($) {
// if (window.location.pathname.startsWith('/product/')) return;
//
// $('.product-slider-container').each(function() {
// const container = $(this);
// const slider = container.find('.product-image-slider');
// const items = slider.find('.slider-item');
// let currentIndex = 0;
//
// // Hide all except first
// items.css({ position: 'absolute', opacity: 0, transition: 'opacity 0.3s ease' });
// items.eq(currentIndex).css({ opacity: 1, position: 'relative' });
//
// // Create and insert dots
// if (items.length <= 1) return;
//
// const dotsContainer = $('<div class="slider-dots"></div>');
//
// items.each(function(i) {
// const dot = $('<span class="slider-dot"></span>');
// if (i === 0) dot.addClass('active');
// dot.on('click', function() {
// currentIndex = i;
// updateSlide();
// });
// dotsContainer.append(dot);
// });
//
// container.append(dotsContainer);
//
// // Slide update function
// function updateSlide() {
// items.css({ opacity: 0, position: 'absolute' });
// items.eq(currentIndex).css({ opacity: 1, position: 'relative' });
// dotsContainer.find('.slider-dot').removeClass('active')
// .eq(currentIndex).addClass('active');
// }
//
// // Touch swipe
// let touchStartX = 0;
// let touchEndX = 0;
//
// slider.on('touchstart', function(e) {
// touchStartX = e.originalEvent.touches[0].clientX;
// });
//
// slider.on('touchend', function(e) {
// touchEndX = e.originalEvent.changedTouches[0].clientX;
// const delta = touchEndX - touchStartX;
//
// if (Math.abs(delta) > 50) {
// if (delta < 0) {
// currentIndex = (currentIndex + 1) % items.length;
// } else {
// currentIndex = (currentIndex - 1 + items.length) % items.length;
// }
// updateSlide();
// }
// });
//
// // Optional: support prev/next buttons too
// container.find('.slider-prev').on('click', function() {
// currentIndex = (currentIndex - 1 + items.length) % items.length;
// updateSlide();
// });
//
// container.find('.slider-next').on('click', function() {
// currentIndex = (currentIndex + 1) % items.length;
// updateSlide();
// });
// });
//});