jQuery autohide element after 5 seconds

前端 未结 8 1387
刺人心
刺人心 2020-11-29 17:53

Is it possible to automatically hide an element in a web page 5 seconds after the form loads using jQuery?

Basically, I\'ve got

相关标签:
8条回答
  • 2020-11-29 18:33

    This is how you can set the timeout after you click.

    $(".selectorOnWhichEventCapture").on('click', function() {
        setTimeout(function(){
            $(".selector").doWhateverYouWantToDo();
        }, 5000);
    });
    

    //5000 = 5sec = 5000 milisec

    0 讨论(0)
  • 2020-11-29 18:34
    $(function() {
        // setTimeout() function will be fired after page is loaded
        // it will wait for 5 sec. and then will fire
        // $("#successMessage").hide() function
        setTimeout(function() {
            $("#successMessage").hide('blind', {}, 500)
        }, 5000);
    });
    

    Note: In order to make you jQuery function work inside setTimeout you should wrap it inside

    function() { ... }
    
    0 讨论(0)
  • 2020-11-29 18:34

    jQuery(".success_mgs").show(); setTimeout(function(){ jQuery(".success_mgs").hide();},5000);

    0 讨论(0)
  • 2020-11-29 18:35

    You use setTimeout on you runEffect function :

    function runEffect() {
        setTimeout(function(){
            var selectedEffect = 'blind';
            var options = {};
            $("#successMessage").hide(selectedEffect, options, 500)
         }, 5000);
    }
    
    0 讨论(0)
  • 2020-11-29 18:38
    $('#selector').delay(5000).fadeOut('slow');
    
    0 讨论(0)
  • 2020-11-29 18:43

    I think, you could also do something like...

    setTimeout(function(){
        $(".message-class").trigger("click");
    }, 5000);
    

    and do your animated effects on the event-click...

    $(".message-class").click(function() {
        //your event-code
    });
    

    Greetings,

    0 讨论(0)
提交回复
热议问题