This is the code I applied first
main page!!
<MainProduct>
{products.map((ele, idx) => {
return (
<div key={idx}>
{products.length - 1 === idx ? (
<ModelImages
onClick={() => moveDetailPage(ele.product_seq)}
id={ele.product_seq}
alt={ele.product_name}
src={ele.image_url}
poster={ele.image_url}
ref={ref}
autoPlay
muted
loop
/>
) : (
<ModelImages
onClick={() => moveDetailPage(ele.product_seq)}
id={ele.product_seq}
alt={ele.product_name}
src={ele.image_url}
poster={ele.image_url}
autoPlay
muted
loop
/>
)}
</div>
);
})}
</MainProduct>
---------------------------------------------
index.html!!
<script type="text/javascript">
window.addEventListener('load', videoScroll);
window.addEventListener('scroll', videoScroll);
function videoScroll() {
if (document.querySelectorAll('video[autoplay]').length > 0) {
var windowHeight = window.innerHeight,
videoEl = document.querySelectorAll('video[autoplay]');
for (var i = 0; i < videoEl.length; i++) {
var thisVideoEl = videoEl[i],
videoHeight = thisVideoEl.clientHeight,
videoClientRect = thisVideoEl.getBoundingClientRect().top;
if (
videoClientRect <= windowHeight - videoHeight * 0.5 &&
videoClientRect >= 0 - videoHeight * 0.5
) {
thisVideoEl.play();
} else {
thisVideoEl.pause();
}
}
}
}
</script>
It works, but I get these errors and it slows down a bit
If there is a way to fix the error or an appropriate method, please share it.
No matter how much I google, I can’t find anything.
No matter how much I google, I can’t find anything.