intersection-observer

IntersectionObserver iOS & Safari

為{幸葍}努か 提交于 2021-01-27 04:40:55
问题 My goal is to change position to a video element if the user scrolls further to the video element. I'm using Intersection Observer API because I need to handle the page scroll from an AdForm Banner/iFrame. Here is my code: function createObserver() { var observer; var options = { root: null, rootMargin: "0px", threshold: buildThresholdList() }; observer = new IntersectionObserver(handleIntersect, options); observer.observe(boxElement); } Here is the handleIntersect function: function

One intersectionObserver to observe many elements or one intersectionObserver per element

蓝咒 提交于 2021-01-21 04:25:24
问题 We have a few CustomElements in our page and some of them have an IntersectionObserver relative to the viewport observing them. That number might be increasing as the designer seems to like intersection animations. Will that lead to performance issues? Is it better to have one IntersectionObserver that observes all elements or many IntersectionObservers that only observe one element? 回答1: As already stated, there are a lot of factors to consider! I made the below library specifically for a

IntersectionObserver with React & Hooks

一个人想着一个人 提交于 2021-01-19 06:27:14
问题 I'm trying to track element visibility with React/Hooks and the Intersection Observer API. However, I can't figure out how to set up observation with "useEffect". Does anybody have any idea how could I do that? Mine solution does not work... function MainProvider({ children }) { const [targetToObserve, setTargetToObserve] = useState([]); window.addEventListener("load", () => { const findTarget = document.querySelector("#thirdItem"); setTargetToObserve([findTarget]); }); useEffect(() => {

Reference error: Can't find variable: IntersectionObserver

…衆ロ難τιáo~ 提交于 2020-08-05 05:53:48
问题 I'm trying to use IntersectionObserver in cordova 8.0.0 app which is running on ios 13. When I inspect my app via safari, I see an error on intialization: ReferenceError: Can't find variable: IntersectionObserver This would suggest, that IntersectionObserver is not available, and I should use a polyfill. But! I've read many post claiming that IntersectionObserver is nativly supported in iOS safari 12+. And I kinda assume, that cordova would be running nativly available WKWebView, so it should

JS - Testing code that uses an IntersectionObserver

独自空忆成欢 提交于 2020-07-15 06:32:11
问题 I have a (rather poorly written) javascript component in my application that handles infinite scroll pagination, and i'm trying to rewrite it to use the IntersectionObserver , as described here, however i'm having issues in testing it. Is there a way to drive the behavior of the observer in a QUnit test, i.e. to trigger the observer callback with some entries described in my tests? A possible solution I have come up with is to expose the callback function in the component's prototype and to

IntersectionObserver not working in Safari or iOS

时光毁灭记忆、已成空白 提交于 2020-06-01 07:41:05
问题 The bounty expires in 7 days . Answers to this question are eligible for a +50 reputation bounty. Jascha Goltermann is looking for a canonical answer : I would expect the bounty winner to find a solution for both issues in the form of a working piece of code instead of hints in the right direction. I have a piece of code that adds a different css class to elements depending on whether they're scrolled into or out of the viewport from top or bottom. It uses the Intersection Observer because it

Gatsby - IntersectionObserver is not defined

故事扮演 提交于 2020-05-28 04:38:46
问题 I am trying to build my gatsby project but I am unable due to the IntersectionObserver not being recognised. I use the intersectionObserver inside an InView component: import React, { useRef, useState, useEffect } from 'react' const InView = ({ children }) => { const [boundingClientY, setBoundingClientY] = useState(null) const [direction, setDirection] = useState(null) const [element, setElement] = useState(null) const [inView, setInView] = useState(false) const observer = useRef(new

Why is Intersection Observer adding class to all observed elements upon intersection of first element?

天大地大妈咪最大 提交于 2020-05-16 03:16:24
问题 Pardon my ignorance, as I'm learning. I'm working on getting div s with the class of .entry to animate upon intersection with the Intersection Observer by adding the class of .entry-animation to them. I've never worked with selecting all elements and animating before. Upon the first intersection, all elements simultaneously animate. What am I doing wrong? Here's the demo: JSFiddle Here's the HTML : <div id="content-container"> <div class="content"> <div class="entry"> <h2> Title of Post 1 <

Why is Intersection Observer adding class to all observed elements upon intersection of first element?

坚强是说给别人听的谎言 提交于 2020-05-16 03:15:45
问题 Pardon my ignorance, as I'm learning. I'm working on getting div s with the class of .entry to animate upon intersection with the Intersection Observer by adding the class of .entry-animation to them. I've never worked with selecting all elements and animating before. Upon the first intersection, all elements simultaneously animate. What am I doing wrong? Here's the demo: JSFiddle Here's the HTML : <div id="content-container"> <div class="content"> <div class="entry"> <h2> Title of Post 1 <

IntersectionObserver callback firing immediately on page load

白昼怎懂夜的黑 提交于 2020-03-17 04:54:44
问题 I'm very new to the IntersectionObserver API, and I've been experimenting with this code: let target = document.querySelector('.lazy-load'); let options = { root: null, rootMargin: '0px', threshold: 0 } let observer = new IntersectionObserver(callback, options); observer.observe(target); function callback() { console.log('observer triggered.'); } This seems to work as it should, and callback() is called whenever .lazy-load element enters the viewport, but callback() also fires once when the