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

后端 未结 6 458
终归单人心
终归单人心 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:52

    Since I constantly need to use jQuery together with TweenMax and since TweenMax already took care of all the parsing of various types of transformation strings as well as compatibility issues, I wrote a tiny jquery plugin here (more of a wrap up of gsap's) that could directly access these values like this:

    $('#ele').transform('rotationX') // returns 0
    $('#ele').transform('x')         // returns value of translate-x
    

    The list of properties you could get/set, along with their initial properties:

    perspective: 0
    rotation: 0
    rotationX: 0
    rotationY: 0
    scaleX: 1
    scaleY: 1
    scaleZ: 1
    skewX: 0
    skewY: 0
    x: 0
    y: 0
    z: 0
    zOrigin: 0
    

    Paste from my other answer, hope this helps.

提交回复
热议问题