PDA

View Full Version : How to grab the i: integer reflecting current image?



zakky
07-31-2009, 05:05 PM
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.

ddadmin
07-31-2009, 08:39 PM
Actually, the onslide event handler of the script (see here (http://www.dynamicdrive.com/dynamicindex4/simplegallery_suppliment.htm)) should help you do that already:


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.

zakky
07-31-2009, 10:49 PM
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.

ddadmin
07-31-2009, 11:49 PM
If you're trying to say update the variable "myPicIdNo" with the current slide's index, you would so something like:


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.

zakky
08-01-2009, 08:06 AM
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.