“居中拖动Jquery”对话框

Center Draggable Jquery Dialog

本文关键字:Jquery 对话框 居中拖动 拖动      更新时间:2023-09-26

在过去的几个小时里,我一直在尝试创建一个动画对话框,该对话框将启动抽吸动画,可拖动,关闭时打开时将再次居中。到目前为止,我有它,所以动画启动,它是可拖动的,但当我关闭和打开它时,它被固定在拖动到的相同位置。

我试过使用open函数,在show/hide中完成函数,在函数中设置div/对话框,使用position:center和yeh。。。

无论如何,这是代码:

frm_location.jsp:

//这是一个"a"标签,似乎无法使其正确显示

id="NEW_LOCATION_BUTTON"href="javascript:openDialog('#dialog form','#popupBoxCancel','range-theme','625');"class="btn_sel">

jQueryDialog.js:

函数打开对话框(_dialog、_cancel、_theme、_size){

jQuery(document).ready(function ($) {
        $(_dialog).dialog({
            autoOpen: true,
            width: _size,
            modal: true,
            position: "center",
            resizable: false,
            draggable: true,
            dialogClass: _theme,
            show: {
                effect: "puff",
                percent: "-150",
                duration: 250
            },
            hide: {
                effect: "puff",
                percent: "-150",
                duration: 250,
            },
        });
    $(_cancel).click(function() {
        $(_dialog).dialog("close");
    });

}

看看这个。我不确定你是如何重新打开对话框的,但这应该可以。jsfiddle代码

<div id='dialog'>PUFF</div>
<button id='reopen'>OPEN DIALOG</button>
  $(function () {
    $('#reopen').click(function () {
        $( "#dialog" ).dialog({ position: 'center'});
        $('#dialog').dialog('open');
    });
    $('#dialog').dialog({
        autoOpen: true,
        width: 200,
        modal: true,
        position: "center",
        resizable: false,
        draggable: true,
        show: {
            effect: "puff",
            percent: "-150",
            duration: 250
        },
        hide: {
            effect: "puff",
            percent: "-150",
            duration: 250,
        },
    });
});