Pregunta

When a page loads, a div should appear for like 3 seconds and then automatically disappear. I'm having trouble with the code at the moment. I'm using this code below:

jQuery("#infor").delay(6000).fadeOut("slow");

My HTML is:

<div id="infor">
something
</div>

But it doesn't seem to be working. Does anyone have any idea why this code is not working?

¿Fue útil?

Solución

Is your code within a document.ready block?

$( document ).ready(function() {
    $("#infor").delay(3000).fadeOut("slow");
});

It works for me: http://jsfiddle.net/YdU4z/

Otros consejos

Your syntax appears to be correct (however if you wanted the delay to be for about 3 seconds, you should change the value inside the delay to 3000).

Do you have this code being wrapped within a document-ready block as seen below?

 <script type='text/javascript'>
     //Short-hand for $(document).ready()
     $(function(){
         //Delay for ~3 seconds and then fade out
         $("#infor").delay(3000).fadeOut("slow");
     });
 </script>

Working Example

I would try using the Developer Tools (F12) within your browser to see if any errors are being thrown (within the Console) and also ensure that the version of jQuery you are using supports the functions being called as well.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top