Domanda

How can I with jQuery + jQuery Mobile. Have an popup dialog to disappear after some time. This one I written work to some extent. It will disappear after sometime. However when I click the button to activate it again it doesn't work, unless I refresh the page again.

JavaScript

<script type="text/javascript">
     $(document).on('pageinit', function(e) {
        $('#postnote').click(function() {
            $('#dialog').popup('open', {history: false}).delay(500).fadeOut('slow').hide();
        });
    });
</script>

The page

<div data-role="page" id="addnote">
    <div id="dialog" data-role="popup" data-transition="fade">
        <div data-role="header"><h1>Note posted</h1></div>
    </div>
    <div data-role="header" data-theme="a">
        <h1>Add Note</h1>
    </div>
    <div data-role="content" data-theme="b">
        <textarea id="note" rows="40" name="note"></textarea>
        <a href="#" id="postnote" data-role="button" data-transition="fade" data-theme="b">Post</a>
        <a href="#" data-rel="back" data-role="button" data-transition="slidefade" data-theme="a" data-direction="reverse">Back</a>
    </div><!-- /content -->
</div><!-- /page -->
È stato utile?

Soluzione

You can do it this way.

$(document).on('popupafteropen', '.ui-popup', function() {
 setTimeout(function () {
  $(this).popup('close');
 }, 5000);
});

Altri suggerimenti

Working example: http://jsfiddle.net/Gajotres/6M9ES/

HTML :

<div data-role="page" id="addnote">
    <div data-role="header" data-theme="a">
        <h1>Add Note</h1>
    </div>
    <div data-role="content" data-theme="b">
        <div id="dialog" data-role="popup" data-transition="fade">
            <div data-role="header"><h1>Note posted</h1></div>
        </div>                
        <textarea id="note" rows="40" name="note"></textarea>
        <a href="#" id="postnote" data-role="button" data-transition="fade" data-theme="b">Post</a>
        <a href="#" data-rel="back" data-role="button" data-transition="slidefade" data-theme="a" data-direction="reverse">Back</a>
    </div><!-- /content -->
</div><!-- /page -->  

Javascript:

$(document).on('pageinit', '#addnote', function(){ 
    $('#postnote').click(function() {
        var interval = setInterval(function(){
            $('#dialog').popup('open', {history: false});//.delay(500).fadeOut('slow');
            var intervalClose = setInterval(function(){    
                $('#dialog').popup('close');
                clearInterval(intervalClose);
            },1000);
            clearInterval(interval);
        },1);           
    });      
});
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top