Get the value of -webkit-transform of an element with jquery

后端 未结 6 440
终归单人心
终归单人心 2020-11-29 22:35

I\'m manipulating a div with the new cool css3 way of doing a transform like this:

$(\"#thediv\").css(\"-webkit-transform\",\"translate(-770px, 0px)\");
         


        
6条回答
  •  有刺的猬
    2020-11-29 22:47

    Your matrix is a 4x4 transformation matrix:

    matrix stuff

    The -770 corresponds to the vx. To extract it, construct a WebkitCSSMatrix object:

    var style = window.getComputedStyle($('#thediv').get(0));  // Need the DOM object
    var matrix = new WebKitCSSMatrix(style.webkitTransform);
    
    console.log(matrix.m41);  // -770
    

提交回复
热议问题