Odd Draggable Behavior After Implementing Auto Scroll

我是研究僧i 提交于 2019-12-05 15:04:41

Changing the draggable containment option from window to document worked for me.

$('.drag-handle').draggable({ 
    ...
    containment: "document",
    ...
});

See: http://docs.jquery.com/UI/Draggable#option-containment

To be cross-browser compatible and to avoid wird behavior, I would recommend to use all JQueryUI draggable callbacks.

I read some days ago that the last version of Chrome has some really tricky problems with natives HTML5 draggable events.

For example, I have just checked your web page source code and you are using $('.drag-handle').on('drag', function(){...}); => You should use the drag callback.

I would also recommend to not use window as the scrollable container in your case. You should create a div to wrap all the tables contents and use it as a scroll container. I have already done this implementation in the past and it is working.

Don't forget to set the wrapper ID in the containment option durring the draggable widget creation.

If it always not working, you could also try to overwrite the helper position in the drag callback :

//Save the mouse position in global variables
$(document).mousemove(function(e){
   window.mouseXPos = e.pageX;
   window.mouseYPos = e.pageY;
});

$('[id^="drag-"]').each(function() {
    $(this).draggable({
        opacity: 0.7,
        cursorAt: { top: 15, left: 50 },        
        scroll: true,
        stop: function(){},  
        drag : function(e,ui){            
            //Force the helper position
            ui.position.left = window.mouseXPos - $(this).draggable('option','cursorAt').left;
            ui.position.top = window.mouseYPos- $(this).draggable('option','cursorAt').top; 
        });
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!