TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Canvas-area – A lightweight HTML Controller for one or more canvas children

50 pointsby fangoover 7 years ago

3 comments

macawfishover 7 years ago
Very cool! This looks really helpful for integrating canvas elements within a page.<p>I was thinking of making a similar library for doing smart, reasonably efficient drawing&#x2F;graphical annotation relative to the positions and dimensions of DOM elements in screen space. Right now, my method has been to create a single canvas with fixed positioning and stretch it across the screen.<p>Then, I do the somewhat tedious work of translating between elements&#x27; bounding rectangles and positions into this space.<p>You can see the technique in action here: <a href="https:&#x2F;&#x2F;micahscopes.github.io&#x2F;tangled-web-components&#x2F;examples&#x2F;" rel="nofollow">https:&#x2F;&#x2F;micahscopes.github.io&#x2F;tangled-web-components&#x2F;example...</a><p>The dogs are custom elements and the edges are drawn on a fixed canvas.<p>A big part of why it&#x27;s so tedious to go from DOM coordinates to fixed canvas coordinates is that there&#x27;s not an efficient way to get notified when a DOM object&#x27;s position changes relative to the screen (e.g., because you&#x27;re scrolling or resizing the window) or the body.<p>Right now, with MutationObservers, you can get notified when an objects bounding box changes (ResizeObserver), AFAIK there&#x27;s not an efficient way listen for updates to an objects&#x27; screen-space position, so you have to poll getBoundingClientRect... and it&#x27;s not scalable!<p>Check out the top comment on this discussion: <a href="https:&#x2F;&#x2F;developers.google.com&#x2F;web&#x2F;updates&#x2F;2016&#x2F;10&#x2F;resizeobserver" rel="nofollow">https:&#x2F;&#x2F;developers.google.com&#x2F;web&#x2F;updates&#x2F;2016&#x2F;10&#x2F;resizeobse...</a><p>The question is &quot;where&#x27;s PositionObserver&quot; at? Anybody know?
评论 #16088193 未加载
jitlover 7 years ago
No support for touch events I’m afraid. Didn’t pan or zoom on iOS 11 Safari.
评论 #16088296 未加载
brosky117over 7 years ago
This looks really interesting! What’s the primary use case for this? I read the README and didn’t see any discussion about why this was made.
评论 #16086761 未加载