.textRevealOnScroll,
.stickyTextRevealWrapper {
--text-reveal-from: 0.3; /* 0.3 means 30% from the bottom of the screen (relevant for variation 2) */
--text-reveal-to: 0.8; /* 0.4 means 40% from the top of the screen (relevant for variation 2) */
--text-reveal-before-color: rgba(160, 160, 160, 0.5); /* color before, when text is not revealed, set alpha to 0 for transparent */
--text-reveal-after-color: rgba(0, 0, 0, 1); /* color after, when text is revealed */
--text-reveal-transition-duration: 0.6s; /* easing duration */
--text-reveal-sticky-wrapper-height: 300vh; /* increase or decrease to make the sticky text reveal longer or shorter (relevant for variation 1) */
--text-reveal-sticky-wrapper-height-mobile: 200vh; /*idem, for tablet and mobile */
}
/* don't change anything below this line */
.textRevealOnScroll .elementor-heading-title .line,
.stickyTextRevealWrapper .elementor-heading-title .line {
background: linear-gradient(to right, var(--text-reveal-after-color) 50%, var(--text-reveal-before-color) 56%);
background-size: 230% 100%;
background-position-x: 100%;
color: transparent;
background-clip: text;
-webkit-background-clip: text;
transition: background-position var(--text-reveal-transition-duration);
white-space: nowrap;
}
_::-webkit-full-page-media, _:future, :root .textRevealOnScroll .elementor-heading-title .line,
:root .stickyTextRevealWrapper .elementor-heading-title .line {
transition: 0.14s; /* on safari desktop, force a quick transition to prevent glitchy bug */
}
.stickyTextRevealWrapper {
height: var(--text-reveal-sticky-wrapper-height);
padding: 0;
}
.stickyTextRevealWrapper>.e-con-inner {
padding: 0;
}
.stickyTextRevealContainer {
height: 100vh;
position: sticky;
top: 0;
padding-top: 0;
padding-bottom: 0;
}
@media (max-width:1024px) {
.stickyTextRevealWrapper {
height: var(--text-reveal-sticky-wrapper-height-mobile);
}
}
@media (max-width:768px) {
.textRevealOnScroll,
.stickyTextRevealWrapper {
--text-reveal-from: 0.6; /* eigener Wert für mobile/tablet */
--text-reveal-to: 0.8; /* optional auch anpassbar */
}
}
document.addEventListener('DOMContentLoaded', function () {
let textRevealWrappers = document.querySelectorAll('.stickyTextRevealWrapper, .textRevealOnScroll');
textRevealWrappers.forEach((textRevealWrapper) => {
let textRevealContainer = textRevealWrapper.querySelector('.stickyTextRevealContainer');
let textRevealHeading = textRevealWrapper.querySelector('.elementor-heading-title');
let scrolledRatio = 0;
let textRevealWrapperHeight;
const isMobile = /iPhone|iPad|Android|SamsungBrowser/i.test(navigator.userAgent);
let settings = {
from: parseFloat(window.getComputedStyle(textRevealWrapper).getPropertyValue('--text-reveal-from')),
to: parseFloat(window.getComputedStyle(textRevealWrapper).getPropertyValue('--text-reveal-to')),
isSticky: textRevealContainer && (window.getComputedStyle(textRevealContainer).position === 'sticky' || window.getComputedStyle(textRevealContainer).position === '-webkit-sticky'),
};
let splittedText = new SplitType(textRevealHeading, {
types: "lines"
});
addCSSVariables();
textRevealWrapper.style.setProperty('--scrolled-ratio', scrolledRatio);
function updateValues() {
textRevealWrapperHeight = textRevealWrapper.offsetHeight;
}
updateValues();
let isUpdateScheduled = false;
function manageScrollSticky() {
let textRevealWrapperTop = textRevealWrapper.getBoundingClientRect().top;
let textRevealContainerTop = textRevealContainer.getBoundingClientRect().top;
let windowHeight = window.innerHeight;
scrolledRatio = (textRevealWrapperTop - textRevealContainerTop) / (textRevealWrapperHeight - windowHeight) * -1;
/* clamp scrolledRatio in between 0 and 1 */
scrolledRatio = Math.min(Math.max(scrolledRatio, 0), 1);
textRevealWrapper.style.setProperty('--scrolled-ratio', scrolledRatio);
isUpdateScheduled = false;
splittedText.lines.forEach((line, index) => {
let backgroundXPos = Math.min(Math.max( (1 - (scrolledRatio * splittedText.lines.length - index)) * 100, 0), 100);
line.style.backgroundPositionX = `${backgroundXPos}%`;
});
};
function manageScroll() {
let textRevealWrapperTop = textRevealWrapper.getBoundingClientRect().top;
let windowHeight = window.innerHeight;
scrolledRatio = (textRevealWrapperTop - windowHeight * (1 - settings.from)) / (textRevealWrapperHeight + (windowHeight * (1 - settings.from)) - (windowHeight * settings.to)) * -1;
/* clamp scrolledRatio in between 0 and 1 */
scrolledRatio = Math.min(Math.max(scrolledRatio, 0), 1);
textRevealWrapper.style.setProperty('--scrolled-ratio', scrolledRatio);
isUpdateScheduled = false;
splittedText.lines.forEach((line, index) => {
let backgroundXPos = Math.min(Math.max( (1 - (scrolledRatio * splittedText.lines.length - index)) * 100, 0), 100);
line.style.backgroundPositionX = `${backgroundXPos}%`;
});
};
window.addEventListener('scroll', () => {
if (!isUpdateScheduled) {
isUpdateScheduled = true;
if (settings.isSticky) {
requestAnimationFrame(manageScrollSticky);
} else {
requestAnimationFrame(manageScroll);
}
}
});
let windowsWidth = window.innerWidth;
window.addEventListener("resize", function () {
if (windowsWidth !== window.innerWidth) {
updateValues();
splittedText = new SplitType(textRevealHeading, {
types: "lines"
});
addCSSVariables();
windowsWidth = window.innerWidth;
}
});
function addCSSVariables() {
splittedText.lines.forEach((line, index) => {
/* set --line-index custom property */
line.style.setProperty('--line-index', index);
/* set --line-total custom property */
line.style.setProperty('--line-total', splittedText.lines.length);
if (isMobile) line.style.transition = 'none';
});
}
});
});
.justifiedCarousel {
--carousel-height: 720px;
}
@media (max-width: 1470px) {
.justifiedCarousel {
--carousel-height: 570px;
}
}
@media (max-width: 1024px) {
.justifiedCarousel {
--carousel-height: 570px;
}
}
@media (max-width: 767px) {
.justifiedCarousel {
--carousel-height: 225px;
}
}
/* Neu - sanftere Kurve wie Swiper-Default: */
.justifiedCarousel .swiper-wrapper {
transition-timing-function: cubic-bezier(0.25, 0.46, 0.45, 0.94) !important;
}
.justifiedCarousel.justifiedCarousel.justifiedCarousel.justifiedCarousel :is(.swiper-slide, .e-con, .elementor-element, .elementor-widget-container) {
width: auto;
}
.justifiedCarousel.justifiedCarousel.justifiedCarousel.justifiedCarousel :is(img, .elementor-video, video, .elementor-wrapper) {
height: var(--carousel-height);
width: auto;
}
.justifiedCarousel.justifiedCarousel.justifiedCarousel.justifiedCarousel :is(.elementor-video, video, .elementor-video-iframe) {
height: var(--carousel-height);
width: 100%;
}
@supports not (aspect-ratio:1/1) {
.justifiedCarousel.justifiedCarousel.justifiedCarousel.justifiedCarousel video {
position: relative;
}
}
.justifiedCarousel.justifiedCarousel.justifiedCarousel.justifiedCarousel .elementor-widget-heading {
width: 100%;
box-sizing: border-box;
white-space: normal;
word-break: break-word;
}
.justifiedCarousel.justifiedCarousel.justifiedCarousel.justifiedCarousel .swiper-slide {
display: flex;
flex-direction: column;
align-items: flex-start;
}
.justifiedCarousel.justifiedCarousel.justifiedCarousel.justifiedCarousel .swiper-slide img {
display: block;
flex-shrink: 0;
}
.justifiedCarousel.justifiedCarousel.justifiedCarousel.justifiedCarousel .swiper-slide .elementor-widget-heading {
width: 0;
min-width: 100%;
box-sizing: border-box;
white-space: normal;
word-break: break-word;
}
window.carouselDirections = window.carouselDirections || new Map();
window.addEventListener('load', function () {
let firstJustifiedSwipers = document.querySelector('.justifiedCarousel .swiper, .justifiedCarousel .swiper-container');
let flag = 0;
let interval = setInterval(() => {
try {
initJustifiedSwipers();
flag++;
if ((firstJustifiedSwipers && firstJustifiedSwipers.swiper.passedParams.slidesPerView === 'auto') || flag > 30) {
clearInterval(interval);
if (flag > 30) console.log('Swiper not found');
}
} catch (error) {
console.log(error);
}
}, 100);
});
function getLeftOffset() {
const refContainer = document.querySelector('.karusellbreite');
if (!refContainer) return 0;
const refRect = refContainer.getBoundingClientRect();
return Math.max(0, refRect.left) + 2; // +2px Korrektur
}
function initJustifiedSwipers() {
if (document.querySelector('.elementor-editor-active')) return;
let stopVideoPlaybackOnChange = true;
let justifiedSwipers = document.querySelectorAll('.justifiedCarousel .swiper, .justifiedCarousel .swiper-container');
justifiedSwipers.forEach(justifiedSwiper => {
let settings = justifiedSwiper.swiper.passedParams;
const initialOffset = getLeftOffset();
settings = {
...settings,
breakpoints: {},
slidesPerView: 'auto',
centeredSlides: false,
loop: true,
freeMode: false,
allowTouchMove: false,
shortSwipes: true,
threshold: 6,
speed: 500,
slidesOffsetBefore: initialOffset,
on: {
slideChange: function () {
if (stopVideoPlaybackOnChange) {
this.slides.forEach((slide) => {
let video = slide.querySelector('video');
if (video) video.pause();
});
}
},
init() {
const swiper = this;
window.carouselDirections.set(swiper, 'next');
swiper.slides.forEach(slide => {
slide.removeAttribute("inert");
slide.removeAttribute("aria-hidden");
let video = slide.querySelector('video');
if (video) video.pause();
});
// Swiper zwingen, Loop-Positionen mit dem Offset neu zu berechnen
requestAnimationFrame(() => {
swiper.update();
swiper.slideToLoop(0, 0, false);
});
startSnapAutoplay(swiper);
// Offset bei Resize neu berechnen und Swiper neu ausrichten
let resizeTimeout;
window.addEventListener('resize', () => {
clearTimeout(resizeTimeout);
resizeTimeout = setTimeout(() => {
const newOffset = getLeftOffset();
swiper.params.slidesOffsetBefore = newOffset;
swiper.updateSlidesOffset();
swiper.update();
swiper.slideToLoop(swiper.realIndex, 0, false);
}, 150);
});
},
},
};
justifiedSwiper.swiper.destroy();
new Swiper(justifiedSwiper, settings);
});
}
function startSnapAutoplay(swiper) {
const carouselEl = swiper.el.closest('.justifiedCarousel');
const pauseAfterSnap = 1600;
let isVisible = false;
let hasStarted = false;
let timeoutId = null;
swiper._isPaused = false;
function step() {
if (swiper._isPaused || !isVisible) {
timeoutId = setTimeout(step, 200);
return;
}
const direction = window.carouselDirections.get(swiper) || 'next';
if (direction === 'next') {
swiper.slideNext();
} else {
swiper.slidePrev();
}
timeoutId = setTimeout(step, swiper.params.speed + pauseAfterSnap);
}
if (carouselEl) {
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting && !hasStarted) {
isVisible = true;
hasStarted = true;
timeoutId = setTimeout(step, 400);
} else {
isVisible = entry.isIntersecting;
}
});
}, { threshold: 0.2 });
observer.observe(carouselEl);
}
}
(function () {
function adjustWidthBasedOnAspectRatio(element) {
const style = window.getComputedStyle(element);
const aspectRatio = style.getPropertyValue('--video-aspect-ratio').trim();
const carouselHeight = style.getPropertyValue('--carousel-height').trim();
let aspectRatioValue;
if (aspectRatio.includes(':')) {
const [width, height] = aspectRatio.split(':').map(Number);
aspectRatioValue = width / height;
} else {
aspectRatioValue = parseFloat(aspectRatio);
}
const heightValue = parseFloat(carouselHeight);
const newWidth = heightValue * aspectRatioValue;
element.style.width = `${newWidth}px`;
element.style.minWidth = `${newWidth}px`;
}
const supportsAspectRatio = () => CSS.supports('aspect-ratio', '1/1');
let videos = document.querySelectorAll('.justifiedCarousel video');
if (!supportsAspectRatio()) {
videos.forEach(adjustWidthBasedOnAspectRatio);
let windowWidth = window.innerWidth;
window.addEventListener('resize', function () {
if (windowWidth !== window.innerWidth) {
videos.forEach(adjustWidthBasedOnAspectRatio);
windowWidth = window.innerWidth;
}
});
}
}());