Solved

show cpations in sequence

Posted on 2012-03-29
4
189 Views
Last Modified: 2012-04-08
Hello Experts,

This was a solution by an expert here in expert exchange :-)
The script was for two caption running in a sequence. Now i need to add a third caption but it does not seem to work right. Can you please help?

$(function() {
     $("#captions div:first").hide();
     setInterval("SwapCaption()", 10000);
});
function SwapCaption()
{
    $("#captions>div").fadeToggle('slow', "linear");
	}

Open in new window

0
Comment
Question by:Refael
[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
  • 2
  • 2
4 Comments
 
LVL 7

Expert Comment

by:Lalit Chandra
ID: 37781014
Can you provide the full code of your page ? it will be easier for us to know.
0
 

Author Comment

by:Refael
ID: 37781033
Hi Lalit-Chandra, it was your solution :-)

http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_27650586.html

I Simply need to add one more caption. I tried but there is a problem...
0
 
LVL 7

Accepted Solution

by:
Lalit Chandra earned 500 total points
ID: 37781206
yes,there is problem with the script. it will only run for 2 caption.
But now, below script can handle any number of caption.

Please replace the following script code  with mine previous code

<script>

$(function() {
$("#divImage-Slide>div").hide();
 currentDivToken = 0;
 maxDivCaptionToken = $("#divImage-Slide>div").length -1;
setInterval("SwapImageWithCaption()", 1000);
     
});
function SwapImageWithCaption()
{
$("#divImage-Slide>div").hide();
  $.each($("#divImage-Slide>div"),function(i) {
        if(currentDivToken  == i)
           $(this).show();
  });
      currentDivToken = (currentDivToken  == maxDivCaptionToken ) ? 0 :currentDivToken  + 1;
}
</script>


Simple add the div containing  Caption like as follow

<div id="divImage-Slide" style=" width: 100px;height: 100px;position: relative;">
   <div id="divImage1" style=" width: 100%;height: 100%;position: absolute;top: 0;left: 0;">
       <div id="divCaption1">aaaaaaaaaaaaaaaa</div>
   </div>
   <div id="divImage2" style=" width: 100%;height: 100%;position: absolute;top: 0;left: 0;">
        <div id="divCaption1">Chrysanthemum</div>
   </div>
 <div id="divImage2" style=" width: 100%;height: 100%;position: absolute;top: 0;left: 0;">
        <div id="divCaption1">Hello</div>
   </div>
</div>

Hope this will fix up your issues.
0
 

Author Closing Comment

by:Refael
ID: 37821877
Thank you!
0

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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

630 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