Δίαιτα 2 σε 1: Χάσε 4 κιλά σε έναν μήνα και φρόντισε το δέρμα σου ταυτόχρονα!

");
}
});
// Function to initialize carousel
function initializeCarousel() {
var container = $(".theme-carousel-container");
var carousel = $(".theme-related-articles-carousel");
var items = $(".theme-carousel-item");
var prevBtn = $(".theme-prev-arrow");
var nextBtn = $(".theme-next-arrow");
if (items.length === 0) return;
var itemWidth = items.first().outerWidth(true);
var visibleItems = Math.floor(container.width() / itemWidth);
var position = 0;
var maxPosition = Math.max(0, items.length - visibleItems);
// Touch handling variables
var isDragging = false;
var startX = 0;
var startY = 0;
var currentX = 0;
var currentTranslate = 0;
var startTranslate = 0;
var threshold = 10; // Minimum distance before we decide if horizontal or vertical
var isScrolling = null; // null = undecided, true = vertical scroll, false = horizontal scroll
// Hide prev button initially
prevBtn.css("opacity", "0.5");
// Click handlers for navigation buttons
nextBtn.click(function() {
if (position < maxPosition) {
position++;
updateCarouselPosition();
}
});
prevBtn.click(function() {
if (position > 0) {
position--;
updateCarouselPosition();
}
});
// IMPROVED Touch handling
carousel.on("touchstart", function(e) {
var touch = e.originalEvent.touches[0];
startX = touch.clientX;
startY = touch.clientY;
isDragging = true;
isScrolling = null; // Reset scroll direction
// Get current transform
var transform = container.css("transform");
var matrix = transform.replace(/[^0-9\-.,]/g, "").split(",");
startTranslate = currentTranslate = matrix[4] ? parseInt(matrix[4]) : 0;
container.css("transition", "none");
});
carousel.on("touchmove", function(e) {
if (!isDragging) return;
var touch = e.originalEvent.touches[0];
var deltaX = touch.clientX - startX;
var deltaY = touch.clientY - startY;
// Determine scroll direction on first significant move
if (isScrolling === null) {
if (Math.abs(deltaX) > threshold || Math.abs(deltaY) > threshold) {
// Decide if horizontal or vertical scroll
// More lenient for vertical scrolling
isScrolling = Math.abs(deltaY) > Math.abs(deltaX) * 0.7;
}
}
// If vertical scrolling, let it pass through
if (isScrolling === true) {
isDragging = false;
container.css("transition", "transform 0.3s ease");
return; // Let the browser handle vertical scroll
}
// If horizontal scrolling, handle the carousel
if (isScrolling === false) {
e.preventDefault(); // Only prevent default for horizontal
currentX = deltaX;
var newTranslate = startTranslate + deltaX;
// Add boundaries with elastic effect
var minTranslate = -maxPosition * itemWidth;
var maxTranslate = 0;
if (newTranslate > maxTranslate) {
newTranslate = maxTranslate + (newTranslate - maxTranslate) * 0.3;
} else if (newTranslate < minTranslate) {
newTranslate = minTranslate + (newTranslate - minTranslate) * 0.3;
}
container.css("transform", "translateX(" + newTranslate + "px)");
}
});
carousel.on("touchend", function(e) {
if (!isDragging || isScrolling === true) return;
isDragging = false;
container.css("transition", "transform 0.3s ease");
// Snap to position
if (Math.abs(currentX) > itemWidth * 0.25) {
if (currentX > 0 && position > 0) {
position--;
} else if (currentX < 0 && position < maxPosition) {
position++;
}
}
updateCarouselPosition();
// Reset
isScrolling = null;
currentX = 0;
});
// Mouse drag for desktop (simplified)
var mouseDown = false;
container.on("mousedown", function(e) {
mouseDown = true;
startX = e.clientX;
var transform = container.css("transform");
var matrix = transform.replace(/[^0-9\-.,]/g, "").split(",");
startTranslate = currentTranslate = matrix[4] ? parseInt(matrix[4]) : 0;
container.css("transition", "none");
e.preventDefault();
});
$(document).on("mousemove", function(e) {
if (!mouseDown) return;
var deltaX = e.clientX - startX;
var newTranslate = startTranslate + deltaX;
// Boundaries
var minTranslate = -maxPosition * itemWidth;
var maxTranslate = 0;
newTranslate = Math.max(minTranslate, Math.min(maxTranslate, newTranslate));
container.css("transform", "translateX(" + newTranslate + "px)");
e.preventDefault();
});
$(document).on("mouseup", function(e) {
if (!mouseDown) return;
mouseDown = false;
container.css("transition", "transform 0.3s ease");
var deltaX = e.clientX - startX;
if (Math.abs(deltaX) > itemWidth * 0.25) {
if (deltaX > 0 && position > 0) {
position--;
} else if (deltaX < 0 && position < maxPosition) {
position++;
}
}
updateCarouselPosition();
});
// Update carousel position
function updateCarouselPosition() {
var translateX = -position * itemWidth;
currentTranslate = translateX;
container.css({
"transition": "transform 0.3s ease",
"transform": "translateX(" + translateX + "px)"
});
// Update button states
prevBtn.css("opacity", position <= 0 ? "0.5" : "1");
nextBtn.css("opacity", position >= maxPosition ? "0.5" : "1");
}
// Responsive handling
$(window).resize(function() {
itemWidth = items.first().outerWidth(true);
visibleItems = Math.floor(container.width() / itemWidth);
maxPosition = Math.max(0, items.length - visibleItems);
if (position > maxPosition) {
position = maxPosition;
}
updateCarouselPosition();
});
// Initial setup
updateCarouselPosition();
}
});
Πηγή-Συνέχεια άρθρου: https://www.tlife.gr/fitness/diaita/diaita-2-se-1-xase-4-kila-se-enan-mina-kai-frontise-to-derma-sou-taytoxrona/1127942/