intersection-observer

Angular performance: change detection detached if component is out of viewport

别等时光非礼了梦想. 提交于 2020-01-15 03:22:08
问题 I want detach the change detection for all the compontents out of the current viewport see demo online import { Component, Input, ChangeDetectionStrategy, ChangeDetectorRef, ElementRef, ViewChild, OnInit, OnDestroy, AfterViewInit } from '@angular/core'; @Component({ selector: 'hello', template: `<div #counter>[{{index}}] {{count}}</div>`, styles: [`div { border: 1px solid red; padding: 5px 5px 5px 5px; }`], changeDetection: ChangeDetectionStrategy.OnPush, }) export class HelloComponent

Change style header/nav with Intersection Observer (IO)

你说的曾经没有我的故事 提交于 2019-12-21 00:38:09
问题 Fiddle latest I started this question with the scroll event approach, but due to the suggestion of using IntersectionObserver which seems much better approach i'm trying to get it to work in that way. What is the goal: I would like to change the style ( color + background-color ) of the header depending on what current div / section is observed by looking for (i'm thinking of?) its class or data that will override the default header style ( black on white). Header styling: font-color :

Different callbacks for different targets with Intersection Observer API

老子叫甜甜 提交于 2019-12-13 03:36:13
问题 I'm using the Intersection Observer API on a site. For every instance of using it, I'm using the same config (main viewport). My issue is that I need to have different things happen when the callback is fired. For some, I want to lazy load an image. For some, I want to initialize a carousel, etc. Is there a way to use the same observer for all of these different applications or do I have to use a different observer for each unique callback? 回答1: You can reuse the same intersection observer

intersection observer polyfill not working Safari

和自甴很熟 提交于 2019-12-12 14:12:13
问题 I need to detect if my iframe which is loaded from another domain is in viewport. This works fine native in Chromem,Firefox and IE called Intersection Observer. However this is not working in Safari. There has been created a polyfill for this: Github link and should be working on Safari as well. I tested it using this code: Site A: <html> <head> </head> <body> A lot of text here so the iframe is not inview. A lot of text here so the iframe is not inview. <br> <br> . . . . . . . <br> A lot of

Intersection observer does not work with target with position: fixed

痴心易碎 提交于 2019-12-12 10:36:32
问题 I am trying to invoke a callback via intersection observer. I want the target to be style: "position: fixed" and move it via style.top . I also specified the root element which is an ancestor of the target with style: "position: relative" . But when the target and the observer intersects, the callback function won't be triggered. Are there some limitations I missed? Here is what I typed: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>IO</title> </head> <body> <div style

Should an IntersectionObserver be disconnected when element is removed

喜夏-厌秋 提交于 2019-12-10 14:51:17
问题 In a Single Page Application, elements are often removed and replaced. On elements that are removed from the DOM there could be an IntersectionObserver(or any other kind) For events I never bothered to care because they are bound and triggered on the target so they should be rather harmless to keep. For the IntersectionObserver I'm somewhat worried all instances are checked on any view change. Consider the following part of my Lazy.ts setIntersectionObserver(config:LazyConfig) { let

How to debounce or throttle Intersection Observer?

纵然是瞬间 提交于 2019-12-04 11:56:35
问题 I am using the Intersection Observer API and I was wondering: How can I debounce or throttle the Intersection Observer API? If I want to increase the performance, do you recommend to use a debounce or throttle function? 来源: https://stackoverflow.com/questions/52584084/how-to-debounce-or-throttle-intersection-observer

MS Edge: IntersectionObserver. Does it work for you?

蹲街弑〆低调 提交于 2019-12-02 00:38:53
问题 Before anyone goes to too much effort here, I already have a nasty workaround. I just want to know if anyone has it working. Version 15 of Edge is now released and has support for intersection observer (for lazy loading). I've implemented it and it works fine in all browsers which support it (Chrome and Opera. Firefox and Safari haven't implemented yet) but not at all in Edge. There are no errors thrown, but the callback is never called. handleIntersectionElement(elm) { if (elm && this.state

How do I know the IntersectionObserver scroll direction?

筅森魡賤 提交于 2019-11-27 14:27:00
问题 So, how do I know the scroll direction when the event it's triggered? In the returned object the closest possibility I see is interacting with the boundingClientRect kind of saving the last scroll position but I don't know if handling boundingClientRect will end up on performance issues. Is it possible to use the intersection event to figure out the scroll direction (up / down)? I have added this basic snippet, so if someone can help me. I will be very thankful. Here is the snippet: var