SVG element shifts when using transform-origin in Firefox

后端 未结 1 1141
既然无缘
既然无缘 2021-01-29 13:13

So I have this blueprint that I\'ve recreated as an SVG.

Here is the codepen!

Everything works fine in Chrome, but in Firefox, once the rotation

1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-29 14:07

    Looks like a bug in FF. I have reported it here.

    To work around this bug, you wouldn't want to use different transform-origin coordinates in Firefox. Because when the bug gets fixed it'll be wrong again.

    The fault seems to be a rounding error in the transformation (the door shifts by 0.5 SVG units). So the obvious solution is to scale all the coordinates up so that a shift of 0.5 units won't be noticeable any more.

    For instance, if you multiply the coords by 10, it seems to work (shift becomes much less noticeable). And if the bug gets fixed in the future, you won't need to change anything.

    var room = document.getElementById('g-f-construction-shop');
    
    room.addEventListener('mouseenter', function animateDoors() {
      var doorElement = document.getElementById('g-o-construction-shop-stage-one-door-right-top');
      doorElement.style.transform = 'rotate(90deg)';
        
      setTimeout(function () {
        doorElement.style.transform = 'rotate(0)';
      }, 750);
    });
    .o-whole, .door {
      stroke: #000;
      stroke-width: 10;
      fill: none;
      opacity: 1;
    }
      
    .f {
      fill: #ff6600;
      opacity: 0.1;
    }
      
    .o-door-right-top {
      transition: transform 0.75s;
    }
      
        
          
          
          
          
          
          
          
        
      

    0 讨论(0)
提交回复
热议问题