In this jsFiddle I have an SVG rect that is resizable using interact.js
. There's also a 10px by 10px grid and the .resizable
function has included a 10px by 10 px snap. The objective is to resize the rect and have the edges snap exactly on the grid.
In most cases it works fine, but many times it is not, as you can see in the picture below. Maybe an adjustment needs to be done manually on resizeend
? How to fix this problem?
As Erik said:
With this
target.setAttribute(attr/a, Math.round(v/10)*10)
it seems to work:Full Demo here - https://jsfiddle.net/alexander_L/1mzs36qL/3/ and below: