• Recent Questions
  • Popular Questions

jQuery – Appear for set time.?

Hello. For a web application I creating, when an operation is successful a fade in message will apear using a .p class called “done” in my custom.js file the following javascript applies to it, to make it work:

$(“p.done”).hide().fadeIn(’10000′);

I would like to change this so that instead, the message will fade in, stay for so long, for example: 10 seconds and then fade back out.
Could anyone explain to me how I would code this, or if it’s even possible.
Thank you in advance for any answers.

Karl Roberts 16 – UK

    Nut Bustington7
    Posted 9 months ago

    You need a timer, I’ve used this one in the past with no complaints: http://jquery.offput.ca/every/ Save the file they’re offering and import it into your HTML document like you did the Jquery library.

    Then you should be able to do something like:
    (“p.done”).click(function () {
    $(this).show().fadeIn(’10000′);
    $(this).oneTime(“10000″, function() {
    $(this).hide().fadeOut(’10000′);
    });
    });

      Adam
      Posted 9 months ago

      Either use a plugin, as suggested, or use standard javascript functions to achieve the same:

      $(“p.done”).hide().fadeIn(’10000′);
      window.setTimeout(function()
      {
      $(“p.done”).fadeOut(’2000′).hide();
      }, 10000);

      setTimeout takes two arguments: the first is the function you wish to call, and the second is how many milliseconds until you call the function. In this example, it will fade the paragraph in, taking ten seconds, wait a further ten seconds, and then fade the paragraph out over two seconds.

    Answer this Question :

    You must be logged in to post an answer. Signup Here, it takes 5 seconds :)

    Other Questions