Jquery setting transform-origin to center

后端 未结 3 1801
臣服心动
臣服心动 2021-01-07 15:08

I\'m having troubles with setting the transform-origin of a div to the center of the site.

This is what I have so far:

var xPos = ($(window).outerWid         


        
3条回答
  •  花落未央
    2021-01-07 15:51

    I stumbled upon this thread. For anyone else trying to solve this with the original posters solution please include Zpx-value aswell (third parameter) and it will work with jQuery.

    Example:

    var xPosSTR = 200 + 'px';
    var yPosSTR = 500 + 'px';
    
    $('.element').css({
        'transform-origin':         xPosSTR + ' ' + yPosSTR + ' 0px',
        '-webkit-transform-origin': xPosSTR + ' ' + yPosSTR + ' 0px'
    });
    

    And forgive the ugly JS ;)

提交回复
热议问题