reset main page video when going out of frame
This commit is contained in:
		
							parent
							
								
									e804c7c39c
								
							
						
					
					
						commit
						5e253ef331
					
				
					 1 changed files with 9 additions and 8 deletions
				
			
		| 
						 | 
					@ -67,19 +67,20 @@ const videos = [
 | 
				
			||||||
  const intersectionOptions = {
 | 
					  const intersectionOptions = {
 | 
				
			||||||
    root: marquee,
 | 
					    root: marquee,
 | 
				
			||||||
    rootMargin: "0px",
 | 
					    rootMargin: "0px",
 | 
				
			||||||
    threshold: 1.0,
 | 
					    threshold: 0.0,
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const observer = new IntersectionObserver((entries) => {
 | 
					  const observer = new IntersectionObserver((entries) => {
 | 
				
			||||||
    entries.forEach((entry) => {
 | 
					    entries.forEach((entry) => {
 | 
				
			||||||
 | 
					      const video = entry.target as HTMLVideoElement;
 | 
				
			||||||
      if (!entry.isIntersecting) {
 | 
					      if (!entry.isIntersecting) {
 | 
				
			||||||
        //@ts-expect-error
 | 
					        video.pause();
 | 
				
			||||||
        entry.target.pause();
 | 
					        video.removeAttribute("autoplay")
 | 
				
			||||||
        entry.target.removeAttribute("autoplay")
 | 
					        video.removeAttribute("data-active")
 | 
				
			||||||
        entry.target.removeAttribute("data-active")
 | 
					        video.currentTime = 0;
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        //@ts-expect-error
 | 
					        video.play();
 | 
				
			||||||
        entry.target.play();
 | 
					        video.setAttribute("data-active","")
 | 
				
			||||||
        entry.target.setAttribute("data-active","")
 | 
					 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  },intersectionOptions);
 | 
					  },intersectionOptions);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue