Get translate3d values of a div?

前端 未结 6 738
难免孤独
难免孤独 2020-11-30 12:30

Say a div has this applied to it:

-webkit-transform: translate3d(0px, -200px, 0px)

How could I retrieve those values with jQuery?

6条回答
  •  星月不相逢
    2020-11-30 13:17

    If you update the regular expression to the following it adds supports for those odd cases when your transform has floats:

    /matrix(?:(3d)\(-{0,1}\d+\.?\d*(?:, -{0,1}\d+\.?\d*)*(?:, (-{0,1}\d+\.?\d*))(?:, (-{0,1}\d+\.?\d*))(?:, (-{0,1}\d+\.?\d*)), -{0,1}\d+\.?\d*\)|\(-{0,1}\d+\.?\d*(?:, -{0,1}\d+\.?\d*)*(?:, (-{0,1}\d+\.?\d*))(?:, (-{0,1}\d+\.?\d*))\))/
    

提交回复
热议问题