jQuery UI Dialog / Drag Question

醉酒当歌 提交于 2019-12-14 03:44:52

问题


Using jQuery UI Dialog.

Works great, but currently, when I drag a dialog, it will not move off screen (the entire dialog is always in the viewport).

Is there a way to set up the dialog so I can drag it partially off screen?


回答1:


Sure you can if you extend the jQuery dialog code. Just include this code:

$.ui.dialog.prototype._makeDraggable = function() { 
    this.uiDialog.draggable({
        containment: false
    });
};

It will override the default containment value of 'document' with false which disables the containment.




回答2:


Or you can do it in a simpler and more "jQuery way" ;)

$(document).ready(function(){
    $('#dialog').
    dialog({
        //your dialog options go here
    }).
    dialog("widget").draggable("option","containment","none"); //this chained sequence kills containment  
});



回答3:


I had this same issue and was going to use betamax's solution, but noticed that it effectively replaces some of jQuery UI's built in functionality. So instead I adapted the approach to keep the built in functionality, but also turn containment off by overriding _makeDraggable rather than just outright replacing it:

if (!$.ui.dialog.prototype._makeDraggableBase) {
    $.ui.dialog.prototype._makeDraggableBase = $.ui.dialog.prototype._makeDraggable;
    $.ui.dialog.prototype._makeDraggable = function() {
        this._makeDraggableBase();
        this.uiDialog.draggable("option", "containment", false);
    };
}



回答4:


Play with the option, position. Write your own javascript calls to move the box.

   $('#dialog').dialog('option','position',[500, 100]);

but you cannot move the box out of the view-port, if you want to have such feature, write your own, extending the jquery ui dialog, (Update the code block where it checks for a valid position (valid if the position x,y are in the viewport)



来源:https://stackoverflow.com/questions/6696461/jquery-ui-dialog-drag-question

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!