Solved

show cpations in sequence

Posted on 2012-03-29
4
170 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
  • 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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…

770 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