jQuery Drag/Resize with CSS Transform Scale

前端 未结 13 2011
忘了有多久
忘了有多久 2020-11-27 13:39

I am applying a CSS transform (and the browser specific -webkit, -o etc):

transform: matrix(0.5 , 0 , 0, 0.5, 0 , 0);

to a div then using jQuery\'s draggable

13条回答
  •  没有蜡笔的小新
    2020-11-27 14:17

    None of these solutions worked for me, as for one, I could not transform the parent of the draggables - only the draggables themselves were transformed.

    This is how I fixed this issue:

    $('.draggable').draggable(
    {
        cancel: '.restrict-drag',
        scroll: false,
        containment: '#contain',
    
        start: function(event, ui) 
        {
            ui.position.left = 0;
            ui.position.top = 0;
        },
    
        drag: function(event, ui) 
        {
            ui.position.left = ui.position.left - ($(event.target).width() * Zoom);
            ui.position.top = ui.position.top - ($(event.target).height() * Zoom);
        }
    });
    

    Zoom is by default 0.

    To scale the draggables I did the following:

    function changeZoom(zoom)
    {
        $('.draggable').each(function() { $(this).css('transform-origin', '50% 50%'); $(this).css('transform', 'scale(' + zoom + ')'); });
        Zoom = zoom; // Global Zoom-variable
    }
    

    And everything seems to work allright.

提交回复
热议问题