0

Hi, i'm really new to jquery and i don't know how to solve this. i added following code to blink a div. initially mypopup div is hidden. and 10 seconds after page was loaded this div appears. because of this toggle() method div displays for 10 more seconds before hiding again. if i want to show that div only for 3 second what can i do???

<script type="text/javascript">
    var blink = function(){
	//$('#mypopup').css({left:0px, top:0px}
	$("#mypopup").css({"left": "0px"});
	$("#mypopup").css({"top": "0px"});
        $('#mypopup').toggle();
    };
    $(document).ready(function() {
        setInterval(blink, 10000);
    });
</script>
2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by ddymacek
0

try

setTimeout(blink,3000);
// or possibly your setInterval ... 1000 milliseconds = 1 second,
// you are setting yours to 10000 = 10 seconds, so set it to 3000.
0

Ah ha... thanx... i added a new block of code as well. now it works fine :)

<script type="text/javascript">
    var blink = function(){
	//$('#mypopup').css({left:0px, top:0px}
	$("#mypopup").css({"left": "0px"});
	$("#mypopup").css({"top": "0px"});
        $('#mypopup').toggle();
			setTimeout(hide_div,2000);
		setTimeout(blink,5000);
    };
    $(document).ready(function() {
       // setInterval(blink, 10000);
		setTimeout(blink,5000);
    });
	function hide_div(){
	$('#mypopup').toggle();
	}
</script>

But there is something i want to know. on my previous post i said "because of this toggle() method". but i think that its incorrect. toggle() only display the div right? and by using this setInterval() method, like i said ,blink() function executed 10 seconds after loading the page and it displayed for 10 more seconds and looped the whole thing again and again. Can i know why does it happen that way? is that the way setInterval() works?

Edited by Virangya: n/a

0

The setInterval() method calls a function or evaluates an expression at specified intervals (in milliseconds).
The setInterval() method will continue calling the function until clearInterval() is called, or the window is closed.
The ID value returned by setInterval() is used as the parameter for the clearInterval() method.
Tip: 1000 ms = 1 second.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.