Results 1 to 5 of 5

Thread: How to grab the i: integer reflecting current image?

  1. #1
    Join Date
    Jun 2009
    Location
    Guernsey
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default How to grab the i: integer reflecting current image?

    1) Script Title: Simple Controls Gallery v1.3

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...plegallery.htm

    3) Describe problem:

    When clicking the prev/next controls to scroll to the next pic, I wish to dynamically update a playlist.

    I need to pull the current image integer out from simpleGallery so I can update a variable used within another script, how can this be done?

    I have tried grabbing the:-
    i: integer reflecting current image within collection being shown (0=1st image, 1=2nd etc)

    without success - please help if you can, thanks.

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Actually, the onslide event handler of the script (see here) should help you do that already:

    Code:
    var mygallery=new simpleGallery({
    wrapperid: "simplegallery", //ID of main gallery container,
    dimensions: [400, 265], //width/height of gallery in pixels. Should reflect dimensions of the images exactly
    imagearray: [
    ["amster1.jpg", "http://en.wikipedia.org/wiki/Summer", "_new", ""],
    ["amster2.jpg", "http://en.wikipedia.org/wiki/Winter", "", ""],
    ["amster3.jpg", "", "", ""],
    ["amster4.jpg", "", "", ""]
    ],
    autoplay: [false, 2500, 2], //[auto_play_boolean, delay_btw_slide_millisec, cycles_before_stopping_int]
    persist: true,
    fadeduration: 1000, //transition duration (milliseconds)
    oninit:function(){ //event that fires when gallery has initialized/ ready to run
    },
    onslide:function(curslide, i){ //event that fires after each slide is shown
    //curslide: returns DOM reference to current slide's DIV (ie: try alert(curslide.innerHTML)
    //i: integer reflecting current image within collection being shown (0=1st image, 1=2nd etc)
    }
    })
    Access the "i" parameter to get the index of the current panel being shown.
    DD Admin

  3. #3
    Join Date
    Jun 2009
    Location
    Guernsey
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    I knew where it was, but have not found a way to reference it outside of the object.

    I can get it to write out by:-

    document.getElementById("test").innerHTML="Testing: " + i;

    But ideally I wanted to dynamically update another variable, so:-
    var myPicIdNo = i;

    or

    var myPicIdNo = mygallery.onslide.i ; (I know this is not correct)

    eg: In testing, I even tried to check the wrapperid using:

    var myTestVar = mygallery.wrapperid[0]; No luck
    var myTestVar = mygallery[0].wrapperid; No luck

    I am obviously misunderstanding a fundamental. It is my lack of knowledge, that is hindering me, so I was hoping someone may be able to help me understand how to grab this variable from this object. All my various attempts have failed.

  4. #4
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    If you're trying to say update the variable "myPicIdNo" with the current slide's index, you would so something like:

    Code:
    onslide:function(curslide, i){ //event that fires after each slide is shown
    myPicIdNo=i
    }
    Notice the lack of "Var" in front, to prevent the variable from being a local one.
    DD Admin

  5. #5
    Join Date
    Jun 2009
    Location
    Guernsey
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    ddadmin - thanks

    I am not very experienced in using javascript, I had my php hat on and thought I was creating a global variable, whereas I was, as you kindly highlighted, doing the opposite.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •