Git Product home page Git Product logo

resizeobserver-intersect's Introduction

ResizeObserver polyfill with IntersectionObserver

resizeobserver-intersect's People

Contributors

nekr avatar

Stargazers

Radovan Janjic avatar Cristian Lorsson avatar Greg Martyn avatar Artur Parkhisenko avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

singod

resizeobserver-intersect's Issues

Doesn't trigger as new chat messages come through

Hey so I tried this out in my chat app and as new messages come in, and the message-list target node expands, I thought ResizeObserver should fire(?) It only triggers once on the initial page render in this case... Am I off on how this should work?

    const rs = new ResizeObserver(() => {
      console.log(arguments);
    });
    rs.observe(document.querySelector('.message-list'));

Suggestion to improve detection of resizes

Rather than using granular steps for intersection ratio; why not use two elements?

Given one element A resting on the inside of the right-bottom corner of the target element and one element B resting on the outside of the right bottom corner, i.e. ,

I.e.

------------------------------
| target                     |
|                            |
|                        ----|
|                        | A |
----------------------------------
                             | B |
                             -----

When the target becomes smaller, A will change its intersection from 1 to less than 1.
When the target becomes bigger, B will change its intersection from 0 to more than 0.

When either element changes its intersection, update the top and left offset of A and B to reseat them in the new corner position and then create a record for the ResizeObserver to call back with.

During creation of the record and reseating the detector elements, you would query the DOM for the size of the element.


One of the first arguments against such a solution would be that having to query the DOM is less efficient than directly re-using the intersection area reported by an IntersectionObserver.

However; note that this intersection area cannot be used directly.

ResizeObserver is supposed to report the content box area, whereas the intersection area reported by an IntersectionObserver is based on comparing border boxes. Thus even if you wanted to use the intersection area directly, you'd still need to query the DOM for the target element's border and padding widths and subtract those to arrive at the content area.

At that point you'd be stuck using multiple window.getComputedStyle calls to figure out padding and border to subtract. That is probably going to be atleast as expensive, if not more so, than querying an element's clientWidth and clientHeight.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.