开发者

scriptaculous slideshow

开发者 https://www.devze.com 2022-12-16 23:03 出处:网络
I am trying to make a scriptaculous slideshow but I have no 开发者_运维百科idea how to loop over all the images in the div tag and then check if it is the last image and assign it to the first img. I

I am trying to make a scriptaculous slideshow but I have no 开发者_运维百科idea how to loop over all the images in the div tag and then check if it is the last image and assign it to the first img. I can add the fading and whatnot myself but I have no idea how to loop through them.


How do you store the images for the slideshow? If you use arrays, then you are looking for imageArray.length. Also you may have a look at the source code for lightbox, as it uses prototype and scriptacolous as well and uses arrays for storing grouped images.

In pure JavaScript you would do something this to get the images as an array included in a div with an ID:

getImageArray = function(containerId) {
    var containerElement = document.getElementById(containerId);
    if (containerElement) {
        var imageArray = containerElement.getElementsByTagName("img");
        return imageArray;
    } else {
        return null; // or something similar
    }
}


scriptaculous is built on prototype so you can do

var arrayOfChildren = $('myContainerDIvId').childElements();
// myContainerDiv is the id of the parent Div.
var numberOfChildren = arrayOfChildren.length;
arrayOfChildren[numberOfChildren] will = the last child in the parent div.

then to loop through the children in the parent div you can do

for(i=0; i<numberOfChildren; i++){
  // do something with arrayOfChildren[i]
}
0

精彩评论

暂无评论...
验证码 换一张
取 消