tholman / the-indie-web

A hotspot for indie creations on the web
https://theindieweb.com
GNU General Public License v3.0
254 stars 38 forks source link

Pattern Stretches Inside Triangle #326

Closed TJScalzo closed 4 years ago

TJScalzo commented 4 years ago

When the triangle changes size with the window, the pattern also changes size. So although the pattern inside of the triangle will always load at the same size, if the window size changes, the pattern will end up bigger or smaller than when it loaded.

Example: Screen Recording 2020-01-18 at 10 49 37 PM 2 I'm pretty sure this isn't intentional since the pattern size is reset when the page is reloaded at the new window size.

From what I can tell, this is happening because vw is used to define the size of the canvas. Since the pattern is created when the page loads, it's rendered at the original size of the canvas. But when the window is resized the pattern isn't re-rendered and so it just stretches or squishes to fill the triangle as necessary.

I'm unfamiliar with HTML Canvas, but I'm not sure if there's a way to prevent the pattern from scaling like this without completely changing how the pattern is rendered/created/applied to the canvas.

tholman commented 4 years ago

Yeah, the canvas acts similarly to how an image would in a document. Once its loaded, it holds its size.

The fix will be to clear and re-run the triangle drawing code with an onwindowresize observer.