?
Solved

Execute functions every 10 seconds

Posted on 2008-06-24
6
Medium Priority
?
2,831 Views
Last Modified: 2012-08-14
I would like to have this trigger every X number of seconds.

if (this.activeImage != (this.imageArray.length - 1)){
                this.disableKeyboardNav();
                this.changeImage(this.activeImage + 1);
            }

Open in new window

0
Comment
Question by:bjv211
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 8

Accepted Solution

by:
Chumad earned 750 total points
ID: 21856386
Lookup the setTimeout function... it works like this:

setTimeout("alert(0)", 10000);  //executes alert every 10 seconds

http://www.w3schools.com/htmldom/met_win_settimeout.asp
0
 
LVL 17

Assisted Solution

by:ram_0218
ram_0218 earned 750 total points
ID: 21856424
look setInterval function thats what you'r looking for.
0
 
LVL 1

Author Comment

by:bjv211
ID: 21858612
I thought I could figure it out but i can't.  I want to call the following script every 10 seconds in this attached js file (ie, i want the image to change every 10 seconds.

if (this.activeImage != (this.imageArray.length - 1)){
                this.disableKeyboardNav();
                this.changeImage(this.activeImage + 1);
            }

lightbox.txt
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:Chumad
ID: 21858753
See attached code.
//the very first call to change the image happens here
setTimeOut("changeImage", 10000);
 
function changeImage() {
 
     //changes the image
     if (this.activeImage != (this.imageArray.length - 1)){
           this.disableKeyboardNav();
           this.changeImage(this.activeImage + 1);
     }
 
     //tell it to execute again in 10 seconds
     setTimeOut("changeImage", 10000);
}

Open in new window

0
 
LVL 1

Author Comment

by:bjv211
ID: 21859672
Chumad, where do I place the first call in th js?
0
 
LVL 1

Author Comment

by:bjv211
ID: 21860077
I placed the setTimeOut line inside the changeImage function (code snippet) and then defined the AdvanceShow function directly after.  This way the timer gets set each time an image is changed:
Will it work this way?


   changeImage: function(imageNum) {   
        
        this.activeImage = imageNum; // update global var
 
        // hide elements during transition
        if (LightboxOptions.animate) this.loading.show();
        this.lightboxImage.hide();
        this.hoverNav.hide();
        this.prevLink.hide();
        this.nextLink.hide();
		// HACK: Opera9 does not currently support scriptaculous opacity and appear fx
        this.imageDataContainer.setStyle({opacity: .0001});
        this.numberDisplay.hide();      
        
        var imgPreloader = new Image();
        
        // once image is preloaded, resize image container
        imgPreloader.onload = (function(){
        this.lightboxImage.src = this.imageArray[this.activeImage][0];
		var maxdims = getVisibleArea();
 
 
//    window.alert( 'Width = ' + maxdims[0] );
//	window.alert( 'Height = ' + maxdims[1] );
var ph=0;
var pw=0;
 
		var lb_max_width = maxdims[0]-20; //if you wish to constrain the width (set to 99999 for unlimited size)
		var lb_max_height = maxdims[1]-85; //if you wish to constring the height (set to 99999 for unlimited size)
		var dims = lb_scale_dims(imgPreloader.width, imgPreloader.height, lb_max_width, lb_max_height);
		this.lightboxImage.setStyle({ width: dims[0] + 'px', left: dims[1] + 'px' });
		this.resizeImageContainer(dims[0], dims[1]);
//		this.resizeImageContainer(imgPreloader.width, imgPreloader.height);
        }).bind(this);
        imgPreloader.src = this.imageArray[this.activeImage][0];
     	setTimeOut("this.AdvanceShow()", 5000);
    },
 
AdvanceShow: function() {
     //changes the image
     if (this.activeImage != (this.imageArray.length - 1))
	 {
           this.disableKeyboardNav();
           this.changeImage(this.activeImage + 1);
     }
},

Open in new window

0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question