Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

javascript function to stop show

Posted on 2012-03-22
4
Medium Priority
?
250 Views
Last Modified: 2012-03-28
I modified some code I found to display a slide show and have it working exactly as I want.  I have run into a problem where I cannot stop the show and clear the canvas.  Here is the code to run the slideshow:


// JavaScript Document
  
var imagePaths = [
  "_sites/BBB_homepage.png",
  "_sites/CabezonKidsDental_homepage.png",
  "_sites/djer_homepage.png",
  "_sites/enchanted_homepage.png",
  "_sites/JoeSSausage_homepage.png",
  "_sites/MMCS_homepage.png",
  "_sites/mySRB.png",
  "_sites/PHCP_homepage.png",
  "_sites/smilesforkidsnm_homepage.png",
  "_sites/t2consulting_homepage.png",
  "_sites/Upward_homepage.png",
  "_sites/Webb_based_homepage.png"
];
var showCanvas = null;
var showCanvasCtx = null;
var img = document.createElement("img");
var currentImage = 0;
var revealTimer;
var stopShow = 0;
  
function slideShow() {
  if (!stopShow){
    showCanvas = document.getElementById('Canvas1');
    showCanvasCtx = showCanvas.getContext('2d');

    //clear canvas
    showCanvasCtx.clearRect(0,0,showCanvasCtx.canvas.width,showCanvasCtx.canvas.height);
  
    img.setAttribute('width','500');
    img.setAttribute('height','400');
    switchImage();
    
    //start the animation
    setInterval(switchImage,3000);
  }
}

function switchImage() {
  img.setAttribute('src',imagePaths[currentImage++]);
  if (currentImage >= imagePaths.length)
      currentImage = 0;
    
  showCanvasCtx.globalAlpha = 0.1;
  revealTimer = setInterval(revealImage,100);
}
  
function revealImage() {
  showCanvasCtx.save();
  showCanvasCtx.drawImage(img,100,0,500,400);
  showCanvasCtx.globalAlpha += 0.1;
  if (showCanvasCtx.globalAlpha >= 1.0) clearInterval(revealTimer);
  showCanvasCtx.restore();
}

Open in new window


Here is the function that I wrote thinking that it would stop the slideshow:

function stopSlideShow() {
  //alert('stop show');
  clearInterval(revealTimer);
  stopShow=1;
}

Open in new window

0
Comment
Question by:prostang
  • 2
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 37756522
replace line 23  by :
		var slideTimer; 

Open in new window

line 37, replace :
setInterval(switchImage,3000);

Open in new window

by :
slideTimer = setInterval(switchImage,3000);

Open in new window

line 47, replace :
revealTimer = setInterval(revealImage,100);

Open in new window

by :
revealTimer = setTimeout(revealImage,100); 

Open in new window


and use :
function stopSlideShow() {
			//alert('stop show');
			clearInterval(slideTimer);
			clearTimeout(revealTimer);
			stopShow=1;
		}

Open in new window

0
 

Author Comment

by:prostang
ID: 37757195
When I launch the slideShow function, there is no fading.  All images are now stacked and the alpha is set for the entire canvas to .1.  It does stop the show and allows me to clear.
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 2000 total points
ID: 37757346
Replace anywhere << Timeout >> by << Interval >>
0
 

Author Comment

by:prostang
ID: 37757453
it stops the function, but does not allow to clear the canvas and the information under the image still has an alpha of .1.

http://mjmco.com/MJMCo.html

the web design link will show -view examples when clicked.  
the -view examples runs the slide show, the stop (just for testing now) should (and does stop it).  
When I click any other link, the first command is to clear the canvas, which isn't working now.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
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

916 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