Get divs position after translate3d

前端 未结 3 1555
日久生厌
日久生厌 2021-02-10 00:51

In Javascript, when I move an element using the gpu via the translate3d method, the elements style-left position doesnt change at all. As the cpu isnt even aware any motion has

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-10 01:00

    The other answers that use getBoundingClientRect work, but if you want to get the actual numeric values from a translate3d string, use a RegExp:

    var xyzArray;
    let translate3dValue = 'translate3d(256px, 512px, 0px)';
    xyzArray = translate3dValue.replace(/translate3d|px|\(|\)/gi, '').split(',');
    

提交回复
热议问题