Replies: 4 comments 1 reply
-
@Heydon I presume you're asking about scaling the drawing to always fit within the browser viewport. This is pretty easy, just define your dimensions in the SVG viewbox, and the browser will automatically scale your drawing. For example, this isn't using the perfect freehand JS lib, but my solution is essentially what I've been using over here. |
Beta Was this translation helpful? Give feedback.
-
Heya, this isn't a 👉 But here's the fix: just remove the Your example with just that line removed. You never have to provide a If you need to crop, zoom, etc, then I'd suggest transforming a |
Beta Was this translation helpful? Give feedback.
-
(P.S. Your videos are awesome! Let me know if you have any questions related to content around this lib.) |
Beta Was this translation helpful? Give feedback.
-
Thanks, @steveruizok. To be clear, what I was looking for is the ability for the drawing/paths to scale with the SVG's coordinate system as defined in the @colbyn You'll find the issue descibed above when you set viewBox. |
Beta Was this translation helpful? Give feedback.
-
Really love this tool; draws beautifully!
Something I'm having trouble with is keeping the pointer events / coords synced to the SVG.
It appears I can only get an accurate pointer location—directly under the cursor—if the SVG's
viewBox
matches its width and height inpx
. This can be addressed by dynamically updating theviewBox
, as in this example: https://codesandbox.io/s/objective-violet-e9ck1?file=/src/App.vue.As you can see, I do this viewBox translation on mounting the component with the
setDimensions
function. The remaining issue regards responsive design. If the browser is resized or I zoom out—and the SVG changes size as a result—this goes out of sync again. I have tried using a resizeObserver to address this (commented out) but it means the drawing/path nolonger scales with the SVG.Is there something about the tool that I don't understand or have missed that would make this easier? Or would I have to do something like add a viewBox-to-path-coords translation layer 😣?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions