Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-19-2011, 01:28 PM   PM User | #1
jerrell
New Coder

 
Join Date: Nov 2011
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
jerrell is an unknown quantity at this point
How can I make jQuery's setTimeout load faster?

I'm trying to get setTimeout to load my replay button while my last frame show .Can this be done?

Thank you in advance for any help received.


Code:
$(function(){
	slideShow();
});

function slideShow() {
    var mycounter;
	mycounter = 0;

	$('#replay, .url').hide();  // make sure button is hidden

	/**
	 * Array of images
	 */
	var arr = [ "img/image1.jpg", "img/image2.jpg", "img/image3.jpg","img/image4.jpg", "img/image5.jpg", "img/image6.jpg", "img/image7.jpg","img/image8.jpg","img/image9.jpg"];
		
	/**
	 * Foreach loop
	 */
	
	$.each(arr, function(i, val) {				
		/**
		 * Changing div opacity to 0. 1000 is the time in ms.
		 */
		$("#sImage").animate({opacity: 0.0}, 1000);
		/**
		 * Queue function will place the event in queue
		 * Changing image src after the above animate function is completed
		 */
		$("#sImage").queue(function(){
			$("#sImage").attr("src", val);
			$("#sImage").dequeue();					
		}); 
		/**
		 * Changing div opacity to 1. 1000 is the time in ms.
		 */
		$("#sImage").attr("src", val).animate({opacity: 1.0}, 10000);	
		/**
		 * Queue function will place the event in queue
		 * Here, queue function is used to hold the changing image for 1 second display
		 */				
		$("#sImage").queue(function(){					
			setTimeout(function(){
				$("#sImage").dequeue();
				mycounter++;
				// after $.each start a loop that checks for mycounter=arr.length regularly and mycounter
				setTimeout(checkCounter, 0, mycounter);
			}, 1000); 
							
		}); 
			
	}); 	    
        
        function checkCounter() {
	if(mycounter<arr.length) {
		setTimeout(checkCounter, 0, mycounter);
	} else {
		// mycounter has reached arr.length ... show the button
                $('#replay, .url').fadeIn('fast');
	}
}

	$('#replay, .replay').click(function(){ //replays video after completed
		slideShow();
	});

/*function doClick(){
	$("#replay").trigger("click");
};*/


}
jerrell is offline   Reply With Quote
Old 12-19-2011, 04:14 PM   PM User | #2
jerrell
New Coder

 
Join Date: Nov 2011
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
jerrell is an unknown quantity at this point
I did some research and found a solution using the delay();

Code:
$('.url').delay(90550).fadeIn('slow');
jerrell is offline   Reply With Quote
Reply

Bookmarks

Tags
faster response, jquery, settimeout

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:27 AM.


Advertisement
Log in to turn off these ads.