|
27.02.2021, 01:13
|
Аспирант
|
|
Регистрация: 06.05.2019
Сообщений: 94
|
|
Да, но то мне не подходит! Демо которую я показал, это простой вариант, мне нужно немножко под другую задачу. Этот плагин так как он есть подходит, только он не работает!
|
|
27.02.2021, 01:20
|
|
Профессор
|
|
Регистрация: 27.05.2010
Сообщений: 33,134
|
|
Сообщение от ethereal
|
почему не работает,
|
плагин рассчитан на работу не выше jQuery 2.2
|
|
27.02.2021, 01:22
|
|
Профессор
|
|
Регистрация: 27.05.2010
Сообщений: 33,134
|
|
Сообщение от ethereal
|
Да, но то мне не подходит!
|
чем не подходит предложенный код? если он делает тоже самое что плагин?
|
|
27.02.2021, 01:25
|
Аспирант
|
|
Регистрация: 06.05.2019
Сообщений: 94
|
|
Не работает даже с jQuery не выше 2.2
|
|
27.02.2021, 01:28
|
Аспирант
|
|
Регистрация: 06.05.2019
Сообщений: 94
|
|
Как мне тот код внедрить в это:
$(function() {
$('.site--video').on('inview', function(event, isInView, topOrBottomOrBoth) {
if (isInView) {
$(this).bgVideo();
$(this).get(0).play();
} else {
$(this).get(0).pause();
$(this).get(0).currentTime = 0;
}
});
$('.site--image---video').on('inview', function(event, isInView) {
if (isInView) {
$(this).addClass( "show" );
} else {
$(this).removeClass( "show" );
}
});
});
|
|
27.02.2021, 01:32
|
|
Профессор
|
|
Регистрация: 27.05.2010
Сообщений: 33,134
|
|
Сообщение от ethereal
|
Не работает даже с jQuery не выше 2.2
|
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
body {
width: 3000px;
height: 3000px;
}
.element {
width: 300px;
height: 300px;
float: left;
margin: 10px;
background: coral;
}
.visible.element {
background: skyblue;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.inview/1.0.0/jquery.inview.min.js"></script>
<script>
$(function() {
$('.element').on('inview', function (event, visible, topOrBottomOrBoth) { console.log(visible)
if (visible == true) {
// element is now visible in the viewport
if (topOrBottomOrBoth == 'top') {
// top part of element is visible
} else if (topOrBottomOrBoth == 'bottom') {
// bottom part of element is visible
} else {
// whole part of element is visible
$(this).addClass("visible");
}
} else {
// element has gone out of viewport
$(this).removeClass("visible");
}
});
});
</script>
</head>
<body>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
<div class="element"></div>
</body>
</html>
|
|
27.02.2021, 01:38
|
Аспирант
|
|
Регистрация: 06.05.2019
Сообщений: 94
|
|
Но все ровно не работает по горизонтале, а в комментарий написано // whole part of element is visible
|
|
27.02.2021, 01:49
|
|
Профессор
|
|
Регистрация: 27.05.2010
Сообщений: 33,134
|
|
Сообщение от ethereal
|
Как мне тот код внедрить в это:
|
document.addEventListener('DOMContentLoaded', function() {
const lazyAnimate = divs => {
divs.forEach(el => {
let isInView = el.intersectionRatio > .4;
let div = el.target;
if (div.classList.contains('site--image---video')) div.classList.toggle('show', isInView);
else {
if (isInView) {
div.play();
//$(div).bgVideo();
} else {
div.pause();
div.currentTime = 0;
}
}
});
}
let observer = new IntersectionObserver(lazyAnimate, {
rootMargin: "100px",
threshold: [0.1, 0.8] //настроить видимость
});
let container = document.querySelectorAll('.site--video, .site--image---video');
container.forEach(div => observer.observe(div))
});
|
|
|
|