Saeid Saeid - 3 months ago 10
Javascript Question

How to get the close2() function to work in this JavaScript?

I have written this JavaScript code. If I un-comment the code , close2() function doesn't work! What is the problem with it?

<script type="text/javascript" src="/files/js/jquery.min.js"></script>

<script type="text/javascript">
/*
$("#popup-0").hide();
$("#popup-1").hide();
$("#popup-2").hide();
$("#popup-3").hide();
$("#popup-4").hide();

$("#popup-0").delay(100000).show(1000);
$("#popup-1").delay(6000).show(1000);
$("#popup-2").delay(30000).show(1000);
$("#popup-3").delay(18000).show(1000);
$("#popup-4").delay(12000).show(1000);

$("#popup-0").delay(150000).hide();
$("#popup-1").delay(110000).hide();
$("#popup-2").delay(70000).hide();
$("#popup-3").delay(68000).hide();
$("#popup-4").delay(52000).hide();
*/
function close2(i)
{
$("#popup-"+i).hide(1000);
}

</script>

Answer

The method hide(duration) will wait for the animation queue provided to that element, you can avoid that by setting queue option.

$("#popup-"+i).hide({duration:1000,queue:false});


or use stop() method to stop currently-running animation

$("#popup-"+i).stop().hide(1000);


or use hide() without any argument which also work as per docs

Note that .hide() is fired immediately and will override the animation queue if no duration or a duration of 0 is specified.

Comments