jQuery UI Draggable + CSS Transform Causes “Jumping”

后端 未结 6 1188
既然无缘
既然无缘 2021-02-08 06:09

EDIT: I solved it. But StackOverflow isn\'t letting me mark my answer as the solution, so I simply am not going to.

I\'m having an issue with regard to

6条回答
  •  梦如初夏
    2021-02-08 06:40

    //css3 transform bug with jquery ui drag - fixed(works fine whether position, absolute or relative)
    var __dx;
    var __dy;
    var __scale=0.5;
    var __recoupLeft, __recoupTop;
    
    $("#draggable").draggable({
        //revert: true,
        zIndex: 100,
        drag: function (event, ui) {
            //resize bug fix ui drag `enter code here`
            __dx = ui.position.left - ui.originalPosition.left;
            __dy = ui.position.top - ui.originalPosition.top;
            //ui.position.left = ui.originalPosition.left + ( __dx/__scale);
            //ui.position.top = ui.originalPosition.top + ( __dy/__scale );
            ui.position.left = ui.originalPosition.left + (__dx);
            ui.position.top = ui.originalPosition.top + (__dy);
            //
            ui.position.left += __recoupLeft;
            ui.position.top += __recoupTop;
        },
        start: function (event, ui) {
            $(this).css('cursor', 'pointer');
            //resize bug fix ui drag
            var left = parseInt($(this).css('left'), 10);
            left = isNaN(left) ? 0 : left;
            var top = parseInt($(this).css('top'), 10);
            top = isNaN(top) ? 0 : top;
            __recoupLeft = left - ui.position.left;
            __recoupTop = top - ui.position.top;
        },
        stop: function (event, ui) {
            $(this).css('cursor', 'default');
            //alternate to revert (don't use revert)
            $(this).animate({
                left: $(this).attr('oriLeft'),
                top: $(this).attr('oriTop')
            }, 1000)
        },
        create: function (event, ui) {
            $(this).attr('oriLeft', $(this).css('left'));
            $(this).attr('oriTop', $(this).css('top'));
        }
    });
    

提交回复
热议问题