<style>
.stleft-icon, .stright-icon {
display: block; /* Замените block на none, чтобы полностью скрыть иконки управления */
width: 40px;
user-select: none;
transition: transform 0.3s ease;
}
.stleft-icon:hover, .stright-icon:hover {
transform: scale(1.1);
}
.stright-icon {
margin-bottom: 120px;
}
.uc-st-wrapper {
overflow: hidden;
display: flex;
z-index: 100;
}
.uc-st-container {
position: relative;
display: flex;
overflow: hidden;
scroll-behavior: smooth;
}
.uc-story {
min-width: 100vw;
width: 100vw;
}
#stleft {
display: none;
position: absolute;
top: 0;
left: 0;
width: 40px;
height: 100%;
cursor: pointer;
z-index: 9999999999;
align-items: center;
justify-content: center;
padding-left: 20px;
}
#stright {
display: none;
position: absolute;
top: 0;
right: 0;
width: 40px;
height: 100%;
cursor: pointer;
z-index: 9999999999;
margin-top: 60px;
align-items: center;
justify-content: center;
padding-right: 20px;
}
.indicator-wrapper {
display: none;
position: absolute;
top: 0;
right: 0;
width: 100%;
height: 2px;
background-color: transparent;
margin-top: 10px;
z-index: 9999999999;
}
.stindicators {
display: flex;
height: 100%;
z-index: 9999999999;
padding-left: 10px !important;
padding-right:10px !important;
}
.stindicators .indicator {
flex: 1;
background-color: rgba(255, 255, 255, 0.5);
border-radius: 5px;
position: relative;
margin: 0 1px;
z-index: 9999999999;
}
.stindicators .indicator.fill {
background-color: white;
transition: width 0.1s linear;
z-index: 9999999999;
}
@media screen and (max-width: 980px) {
.stleft-icon, .stright-icon {
display: none;
}
}
</style>
<div id='stleft'>
<!--Ссылка на иконку для левой кнопки-->
<img src='https://lf-cloud.ru/uploads/66cc43eed8de1.svg' class="stleft-icon">
</div>
<div id='stright'>
<!--Ссылка на иконку для правой кнопки-->
<img src='https://lf-cloud.ru/uploads/66cc43fabbbda.svg' class="stright-icon">
</div>
<div class='indicator-wrapper'>
<div class='stindicators'></div>
</div>
<script>
var stWrapper = document.querySelector('.uc-st-wrapper');
var stContainer = document.querySelector('.uc-st-container');
var stleftButton = document.getElementById('stleft');
var strightButton = document.getElementById('stright');
var indicatorWrapper = document.querySelector('.indicator-wrapper');
var isScrolling = false;
var visibleSlideIndex = 0;
function updateSlideVisibility() {
var slides = document.querySelectorAll('.uc-story');
slides.forEach(function(slide, index) {
slide.style.display = (index === visibleSlideIndex) ? 'block' : 'none';
});
}
function slideRight() {
if (!isScrolling) {
isScrolling = true;
var slides = document.querySelectorAll('.uc-story');
visibleSlideIndex = (visibleSlideIndex + 1) % slides.length;
updateSlideVisibility();
updateIndicators();
setTimeout(function() {
isScrolling = false;
}, 1000);
}
}
function slideLeft() {
if (!isScrolling) {
isScrolling = true;
var slides = document.querySelectorAll('.uc-story');
visibleSlideIndex = (visibleSlideIndex - 1 + slides.length) % slides.length;
updateSlideVisibility();
updateIndicators();
setTimeout(function() {
isScrolling = false;
}, 1000);
}
}
function createIndicators() {
var indicatorsContainer = document.querySelector('.stindicators');
indicatorsContainer.innerHTML = '';
var slides = document.querySelectorAll('.uc-story');
slides.forEach(function() {
var indicator = document.createElement('div');
indicator.className = 'indicator';
indicatorsContainer.appendChild(indicator);
});
updateIndicators();
}
function updateIndicators() {
var indicators = document.querySelectorAll('.stindicators .indicator');
indicators.forEach(function(indicator, index) {
if (index === visibleSlideIndex) {
indicator.classList.add('fill');
} else {
indicator.classList.remove('fill');
}
});
}
function hideButtons() {
if (stleftButton !== null) {
stleftButton.style.display = 'none';
}
if (strightButton !== null) {
strightButton.style.display = 'none';
}
if (indicatorWrapper !== null) {
indicatorWrapper.style.display = 'none';
}
}
function showButtons() {
if (stleftButton !== null) {
stleftButton.style.display = 'flex';
}
if (strightButton !== null) {
strightButton.style.display = 'flex';
}
if (indicatorWrapper !== null) {
indicatorWrapper.style.display = 'block';
}
}
if (stleftButton !== null && strightButton !== null) {
stleftButton.addEventListener('click', function() {
slideLeft();
});
strightButton.addEventListener('click', function() {
slideRight();
});
}
var slides = document.querySelectorAll('.uc-story');
stWrapper.appendChild(stContainer);
slides.forEach(function(slide) {
stContainer.appendChild(slide);
});
createIndicators();
var touchstartX = 0;
var touchendX = 0;
var touchstartY = 0;
var touchendY = 0;
stContainer.addEventListener('touchstart', function(event) {
touchstartX = event.changedTouches[0].screenX;
touchstartY = event.changedTouches[0].screenY;
});
stContainer.addEventListener('touchend', function(event) {
touchendX = event.changedTouches[0].screenX;
touchendY = event.changedTouches[0].screenY;
handleGesture();
});
function handleGesture() {
var xDiff = touchendX - touchstartX;
var yDiff = touchendY - touchstartY;
if (Math.abs(xDiff) > Math.abs(yDiff)) {
if (xDiff < 0) {
slideRight();
} else if (xDiff > 0) {
slideLeft();
}
} else {
if (yDiff > 0) {
var tPopupClose = document.querySelector('.t-popup__close');
if (tPopupClose) {
tPopupClose.click();
}
}
}
}
window.addEventListener('resize', function() {
var slideWidth = stContainer.querySelector('.uc-story').offsetWidth;
var scrollDistance = stContainer.scrollLeft;
var index = Math.round(scrollDistance / slideWidth);
visibleSlideIndex = index;
updateSlideVisibility();
updateIndicators();
});
var showStoriesButtons = document.querySelectorAll('.show-stories');
showStoriesButtons.forEach(function(button) {
button.addEventListener('click', function() {
showButtons();
var videos = document.querySelectorAll('.uc-story video');
videos.forEach(function(video) {
video.muted = false;
});
});
});
var tPopupClose = document.querySelector('.t-popup__close');
if (tPopupClose !== null) {
tPopupClose.addEventListener('click', hideButtons);
}
document.addEventListener('keydown', function(event) {
if (event.key === 'Escape' || event.key === 'Esc') {
hideButtons();
}
});
var observer = new IntersectionObserver(function(entries) {
entries.forEach(function(entry) {
if (entry.isIntersecting) {
var videos = entry.target.querySelectorAll('video');
videos.forEach(function(video) {
video.play();
video.muted = false;
clearTimeout(video.timeout);
video.timeout = setTimeout(function() {
slideRight();
}, video.duration * 1000);
console.log('Длительность видео:', video.duration, 'секунд');
});
} else {
var videos = entry.target.querySelectorAll('video');
videos.forEach(function(video) {
video.pause();
video.currentTime = 0;
clearTimeout(video.timeout);
});
}
});
}, { threshold: 0.5 });
slides.forEach(function(slide) {
observer.observe(slide);
});
updateSlideVisibility();
</script>
<script>
function preventPopupClick(event) {
if (event.target.closest('.t-popup__close')) {
return;
}
event.stopImmediatePropagation();
}
function blockPopupClick() {
const tPopupElement = document.querySelector('.t-popup');
if (tPopupElement) {
tPopupElement.addEventListener('click', preventPopupClick);
}
}
setInterval(blockPopupClick, 100);
</script>