jQuery UI Draggable + CSS Transform Causes “Jumping”

后端 未结 6 1190
既然无缘
既然无缘 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:31

    position:absolute; is indeed problematic. I however found an alternative solution that prevents the jump, while keeping an absolute basis for coordinates and maintain position, by flipping the css position to relative on mousedown, and restore it to absolute on mouseup, such as the following:

    $('#container').on('mousedown', 'canvas', function (e) {
        e.currentTarget.style.position = 'relative';
    }).on('mouseup', 'canvas', function (e) {
        if (e.currentTarget.style.position !== 'absolute'){
            e.currentTarget.style.position = 'absolute';
        }
    });
    

    It works well for mouse events. And to resolve the issue for touch events, along with the 'touchpunch' plugin, I additionally also had to cancel 'click' events (for mobile and touch enabled modality only).

提交回复
热议问题