Solved

show cpations in sequence

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

827 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