How to create a dialog with jQuery that disappears after 3 seconds?

My buttons class: button-stg

My script:

$(document).ready(function(){
    $(".button-stg").click(function(event) {
        event.preventDefault();
        $.ajax($(this).attr('href')).done(function(response) {

        });
    });
});

How do I add this script if I would like to create a popup or dialog containing "Random Text" that disappears after 3 seconds?

+4
source share
2 answers

Use jquery .fadeOut()

$('.popup').fadeOut(3000);

http://jsfiddle.net/gf4vpn9s/3/

or delay combination ()

 $('.popup').delay(3000).fadeOut();

http://jsfiddle.net/gf4vpn9s/2/

+1
source

You can use the setTimeout funtion function for your code like this

setTimeout(function(){
    $(dialog).close();
}, 5000);

Remember that this is a modal class or identifier.

+1
source

Source: https://habr.com/ru/post/1619802/


All Articles