const video = document.querySelector(".video-background"); let src = video.currentSrc…
- User
const video = document.querySelector(".video-background"); let src = video.currentSrc || video.src; console.log(video, src);
/* Make sure the video is 'activated' on iOS */ function once(el, event, fn, opts) { var onceFn = function (e) { el.removeEventListener(event, onceFn); fn.apply(this, arguments); }; el.addEventListener(event, onceFn, opts); return onceFn; }
once(document.documentElement, "touchstart", function (e) { video.play(); video.pause(); });
/* ---------------------------------- / / Scroll Control! */
gsap.registerPlugin(ScrollTrigger);
let tl = gsap.timeline({ defaults: { duration: 1 }, scrollTrigger: { trigger: "#container", start: "top top", end: "bottom bottom", scrub: true } });
once(video, "loadedmetadata", () => { tl.fromTo( video, { currentTime: 0 }, { currentTime: video.duration || 1 } ); });
/* When first coded, the Blobbing was important to ensure the browser wasn't dropping previously played segments, but it doesn't seem to be a problem now. Possibly based on memory availability? */ setTimeout(function () { if (window["fetch"]) { fetch(src) .then((response) => response.blob()) .then((response) => { var blobURL = URL.createObjectURL(response);
var t = video.currentTime; once(document.documentElement, "touchstart", function (e) { video.play(); video.pause(); }); video.setAttribute("src", blobURL); video.currentTime = t + 0.01; });} }, 1000);
this code covert to react js
- Assistant
- User
import React, { useEffect, useRef } from "react"; import { gsap } from "gsap"; import { ScrollTrigger } from "gsap/ScrollTrigger";
gsap.registerPlugin(ScrollTrigger);
const VideoBackground = () => { const videoRef = useRef(null);
useEffect(() => { const video = videoRef.current!; let src = video.currentSrc || video.src;
// Function to add an event listener that runs only once const once = (el, event, fn, opts) => { const onceFn = (e) => { el.removeEventListener(event, onceFn); fn(e); }; el.addEventListener(event, onceFn, opts); return onceFn; }; // Activate video on iOS once(document.documentElement, "touchstart", () => { video.play(); video.pause(); }); // Setup GSAP and ScrollTrigger let tl = gsap.timeline({ defaults: { duration: 1 }, scrollTrigger: { trigger: "#container", start: "top top", end: "bottom bottom", markers: true, scrub: true, }, }); once(video, "loadedmetadata", () => { tl.fromTo( video, { currentTime: 0, }, { currentTime: video.duration || 1, } ); }); // Blobbing management setTimeout(() => { if (window.fetch) { fetch(src) .then((response) => response.blob()) .then((blob) => { const blobURL = URL.createObjectURL(blob); const currentTime = video.currentTime; once(document.documentElement, "touchstart", () => { video.play(); video.pause(); }); video.setAttribute("src", blobURL); video.currentTime = currentTime + 0.01; }); } }, 1000); - Assistant
- User
window.fetch error
This condition will always return true since this function is always defined. Did you mean to call it instead?
- Assistant
- User
index.css *, *::after, *::before { padding: 0; margin: 0; box-sizing: border-box; }
html, body, #root { overscroll-behavior: none; height: 400vh; }
video { width: 100%; height: 100%; }
- Assistant
- User
no not use position fixed because more sectionn come after this
- Assistant