开发者

How to close jQuery UI dialog from within an interval?

开发者 https://www.devze.com 2023-02-25 20:08 出处:网络
I\'m trying to close a jQuery UI dialog from within an interval.What I have seems like it should work, but for some reason it won\'t.I had some trouble animating the progress bar inside of the modal w

I'm trying to close a jQuery UI dialog from within an interval. What I have seems like it should work, but for some reason it won't. I had some trouble animating the progress bar inside of the modal window, but got that开发者_如何学Go figured out. Since that didn't want to animate the normal way, I wonder if the dialog doesn't want to close the normal way either.

Note: It always makes it to "Made it!".

    if(data.version != localStorage.getItem("Sync Version")) {
        //Start the progress bar.
        $("#progress-bar").progressbar({
            value:0,
            complete : function(event, ui) {
                $("#modal-message").dialog("close");
            }
        });

        //Modal Width
        modalWidth = 400;

        //Throw up a modal.
        $("#modal-message").dialog({
            height: 300,
            width: modalWidth,
            modal: true
        });

        //Queries to execute on initial sync.
        qt = 0;
        queryThreshold = 4000;

        //Start the interval
        $(function() {
            var progress = setInterval(function() {
                var qval = Math.floor(100*(qt / queryThreshold));

                if (qval == 100) {
                    console.log("Made it!");
                    $("#modal-message").dialog("close");
                    clearInterval(progress);
                } else {
                    //$("#progress-bar").progressbar("option", "value", qval);
                    $("#progress-bar .ui-progressbar-value").animate({width : qval+"%"}, modalWidth);
                }_
            },750);
        });

        //Save the newest sync verison.
        localStorage.setItem("Sync Version", data.version);

        //Perform a full sync.
        full_sync();
    }


Do you have this code being called after the DOM has been loaded? I assume so or $("#progress-bar").progressbar({ /*...*/ }); and $("#modal-message").dialog({ /*...*/ }); may not actually be doing anything.

That said, try storing the dialog in a variable like so:

var mydialog = $("#modal-message").dialog({

and then referencing that in your function:

//$("#modal-message").dialog("close");
//becomes:
mydialog.dialog("close");


try putting:

    $("#modal-message").dialog({
        height: 300,
        width: modalWidth,
        modal: true
    });

inside the $(function() {...})

0

精彩评论

暂无评论...
验证码 换一张
取 消