I have seen your test, for me there is no problem.
It’s true that your canvas get resized when coming back to normal state, but it’s due to the resize of your “mydiv” element. Check its bounding box with developer tool and see what’s changing.
To resolve that, it’s also pretty straight forward, just control the size and position of your “mydiv” with css so that it won’t be resized or moved around.