title: How do you add an annotation to a website without altering the layout?
body: <p>I'm working on a hobby project similar to <a href="https://app.markup.io/invite/accept/OVCnNZL2" rel="nofollow noreferrer">markup.io</a> where you can load in any website and annotate it. I can't figure out how to add an annotation that behaves like it does in markup.io:</p>
  <ul>
  <li>Doesn't interrupt the styling or layout of the website you are annotating</li>
  <li>The annotation keeps the correct position when scrolling and resizing the window</li>
  </ul>
  <p>From what I can see they place an absolute positioned div inside the element that you clicked on. From my understanding by reading <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/position#:%7E:text=elements%20is%20undefined.-,absolute,determined%20by%20the%20values%20of%20top%2C%20right%2C%20bottom%2C%20and%20left.,-This%20value%20creates" rel="nofollow noreferrer">the docs</a> that div would position itself based on the closest positioned ancestor. How would you calculate the correct top and left values to position the annotation to where the user clicked? Is there a better way to do this?</p>
  <p>I'm using React if that matters.</p>
  <p><strong>Things that I have tried:</strong></p>
  <ol>
  <li>Append the following bit of html to the element that was clicked:</li>
  </ol>
  <pre><code>&lt;div style=&quot;width:0px; height:0px; position:relative;&quot;&gt;
  &lt;div style=&quot;width:50px;height:50px;position:absolute; &quot;&gt;this is the annotation &lt;/div&gt; 
  &lt;/div&gt;
  </code></pre>
  <p><strong>Problem:</strong> This would mess with the page layout because of the relative positioned div that is not ignored by the document flow.</p>
  <ol start="2">
  <li>Create fixed overlay over the entire page. Get the css selector of the clicked element. Draw annotation on the fixed overlay at the x,y position of the element.</li>
  </ol>
  <p><strong>Problem:</strong> Whenever the user would scroll or resize the window the annotation would need to be redrawn at the new position of the element. I used getBoundintClientRect to get the new position and this would cause a reflow and caused the whole website to have severe perfomance issues when dealing with 100+ annotations.</p>
  <p>Hopefully someone can point me in the right direction!</p>