Adding a text caption to this slideshow script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Wolfman
    New Member
    • Apr 2007
    • 21

    Adding a text caption to this slideshow script

    Hi guys

    I've been using this, my favorite slideshow script for its simplicity. Now I'd like to add a text caption to each image that rotates in-kind, but I'm having trouble working out the dynamics.
    Here's the current script:

    <SCRIPT LANGUAGE="JAVAS CRIPT" TYPE="TEXT/JAVASCRIPT">
    <!--

    myPix = new Array(
    "images/picture01.jpg",
    "images/picture02.jpg",
    "images/picture03.jpg",
    "images/picture04.jpg")
    thisPic = 0
    imgCt = myPix.length - 1

    function chgSlide(direct ion) {
    if (document.image s) {
    thisPic = thisPic + direction
    if (thisPic > imgCt) {
    thisPic = 0
    }
    if (thisPic < 0) {
    thisPic = imgCt
    }
    document.myPict ure.src=myPix[thisPic]
    }
    }

    // -->
    </SCRIPT>

    <P><IMG SRC="images/picture01.jpg" NAME="myPicture " WIDTH="300" HEIGHT="200"></P>
    <A HREF="javascrip t:chgSlide(-1)"><< Back</A> <A HREF="javascrip t:chgSlide(1)"> Forward >></A>

    I was thinking that I could add this second array, but am stuck on how to integrate the resulting variable into the body:

    myCap = new Array(
    "Text Caption 01",
    "Text Caption 02",
    "Text Caption 03",
    "Text Caption 04")
    thisCap = 0
    imgCt = myCap.length - 1

    function chgSlide(direct ion) {
    if (document.image s) {
    thisCap = thisCap + direction
    if (thisCap > imgCt) {
    thisCap = 0
    }
    if (thisCap < 0) {
    thisCap = imgCt
    }
    document.myCapt ion.src=myCap[thisCap]
    }
    }

    Any ideas?
  • Wolfman
    New Member
    • Apr 2007
    • 21

    #2
    I found a simple way to use a textarea tag, but it looks junky.

    <TEXTAREA NAME=myCaption> </TEXTAREA>

    I'd like for the text to appear as if it was simple HTML text.

    Comment

    • Wolfman
      New Member
      • Apr 2007
      • 21

      #3
      I tried combining the variables to no avail, but I think I'm getting closer. This variant tells me, however, that 'myCaption' is null, even though I follow the other array's scripting precisely. What am I doing wrong?

      <SCRIPT LANGUAGE="JAVAS CRIPT" TYPE="TEXT/JAVASCRIPT">
      <!--

      myPix = new Array(
      "images/01.jpg",
      "images/02.jpg",
      "images/03.jpg")
      thisPic = 0
      imgCt = myPix.length - 1

      myTxt = new Array(
      "Caption 1",
      "Caption 2",
      "Caption 3")
      thisTxt = 0
      txtCt = myTxt.length - 1

      function chgSlide(direct ion) {
      if (document.image s) {
      thisPic = thisPic + direction
      thisTxt = thisTxt + direction
      if (thisPic > imgCt) {
      thisPic = 0
      thisTxt = 0
      }
      if (thisPic < 0) {
      thisPic = imgCt
      thisTxt = txtCt
      }
      document.myPict ure.src=myPix[thisPic]
      document.myCapt ion.src=myTxt[thisTxt]
      }
      }

      // -->
      </SCRIPT>


      <P><IMG SRC="images/01.jpg" NAME="myPicture " WIDTH="50" HEIGHT="40" ALT="Slideshow" ></P>
      <SCRIPT LANGUAGE="JAVAS CRIPT" TYPE="TEXT/JAVASCRIPT">
      document.write( myCaption)
      </SCRIPT><BR>
      <A HREF="javascrip t:chgSlide(-1)">Back</A> <A HREF="javascrip t:chgSlide(1)"> Forward</A>

      Comment

      • Logician
        New Member
        • Feb 2007
        • 210

        #4
        Originally posted by Wolfman
        document.myCapt ion.src=myTxt[thisTxt]
        You don't have an element called document.myCapt ion so you cant give it a src property, and even if you could it wouldn't be any use.

        Create a <span> element with whatever CSS styling you want, give it an ID attribute, say 'myCaption', include the function below and use it thus:

        caption('myCapt ion', myTxt[thisTxt]);

        Code:
        function caption(elemId, txt)
        {
         var elem;
         
         if(document.getElementById && (elem=document.getElementById(elemId)))
          if(elem.firstChild)
           elem.firstChild.data=txt;
          else
           elem.appendChild(document.createTextNode(txt)); 
        }
        @ADMIN - Why are we now getting those poxy line numbers that nobody wants?

        Alternatively, try a different slideshow

        Comment

        • Wolfman
          New Member
          • Apr 2007
          • 21

          #5
          Thanks. I'm motivated to use this one because it's very basic - no transition effects, no page refreshing, no fancy text boxes. Just a picture and some text that can be formatted using traditional tags. Will give your corrections a whirl - and thanks.

          Comment

          Working...