Jquery 下一张图片onclick画廊

Jquery 下一张图片onclick画廊,jquery,image,next,Jquery,Image,Next,我有这个图库,我想添加一个onclick事件以转到下一个图像。 我不需要下一个/上一个按钮,只需要让用户看到下一张图片,并保持画廊的循环。 希望有人能给我小费。谢谢 var galleryId = 'gallery'; /* change this to the ID of the gallery list */ var gallery; /* this will be the object reference to the list later on */ var galleryImages;

我有这个图库,我想添加一个onclick事件以转到下一个图像。 我不需要下一个/上一个按钮,只需要让用户看到下一张图片,并保持画廊的循环。 希望有人能给我小费。谢谢

var galleryId = 'gallery'; /* change this to the ID of the gallery list */
var gallery; /* this will be the object reference to the list later on */
var galleryImages; /* array that will hold all child elements of the list */
var currentImage; /* keeps track of which image should currently be showing */
var previousImage;
var preInitTimer;
preInit();

/* functions */

function preInit() {
    /* manages to initially hide the image gallery list
       before even onload is triggered (at which point it's normally too late, and the whole list already
       appeared to the user before being remolded) */
    if ((document.getElementById)&&(gallery=document.getElementById(galleryId))) {
        gallery.style.visibility = "hidden";
        if (typeof preInitTimer != 'undefined') clearTimeout(preInitTimer); /* small Opera fix */
    } else {
        preInitTimer = setTimeout("preInit()",2);
    }
}

function fader(imageNumber,opacity) {
    /* helper function to deal specifically with images and the cross-browser differences in opacity handling */
    var obj=galleryImages[imageNumber];
    if (obj.style) {
        if (obj.style.MozOpacity!=null) {  
            /* Mozilla's pre-CSS3 proprietary rule */
            obj.style.MozOpacity = (opacity/100) - .001;
        } else if (obj.style.opacity!=null) {
            /* CSS3 compatible */
            obj.style.opacity = (opacity/100) - .001;
        } else if (obj.style.filter!=null) {
            /* IE's proprietary filter */
            obj.style.filter = "alpha(opacity="+opacity+")";
        }
    }
}

function fadeInit() {
    if (document.getElementById) {
        preInit(); /* shouldn't be necessary, but IE can sometimes get ahead of itself and trigger fadeInit first */
        galleryImages = new Array;
        var node = gallery.firstChild;
        /* instead of using childNodes (which also gets empty nodes and messes up the script later)
        we do it the old-fashioned way and loop through the first child and its siblings */
        while (node) {
            if (node.nodeType==1) {
                galleryImages.push(node);
            }
            node = node.nextSibling;
        }
        for(i=0;i<galleryImages.length;i++) {
            /* loop through all these child nodes and set up their styles */
            galleryImages[i].style.position='absolute';
            galleryImages[i].style.top=0;
            galleryImages[i].style.zIndex=0;
            /* set their opacity to transparent */
            fader(i,0);
        }
        /* make the list visible again */
        gallery.style.visibility = 'visible';
        /* initialise a few parameters to get the cycle going */
        currentImage=0;
        previousImage=galleryImages.length-1;
        opacity=100;
        fader(currentImage,100);
        /* start the whole crossfade process after a second's pause */
        window.setTimeout("crossfade(100)", 2000);
    }
}

function crossfade(opacity) {
        if (opacity < 120) {
            /* current image not faded up fully yet...so increase its opacity */
            fader(currentImage,opacity);
            /* fader(previousImage,100-opacity); */
            opacity += 10;
            window.setTimeout("crossfade("+opacity+")", 30);
        } else {
            /* make the previous image - which is now covered by the current one fully - transparent */
            fader(previousImage,0);
            /* current image is now previous image, as we advance in the list of images */
            previousImage=currentImage;
            currentImage+=1;
            if (currentImage>=galleryImages.length) {
                /* start over from first image if we cycled through all images in the list */
                currentImage=0;
            }
            /* make sure the current image is on top of the previous one */
            galleryImages[previousImage].style.zIndex = 0;
            galleryImages[currentImage].style.zIndex = 100;
            /* and start the crossfade after a second's pause */
            opacity=0;
            window.setTimeout("crossfade("+opacity+")", 5000);
        }

}

/* initialise fader by hiding image object first */
addEvent(window,'load',fadeInit)



/* 3rd party helper functions */

/* addEvent handler for IE and other browsers */
function addEvent(elm, evType, fn, useCapture) 
// addEvent and removeEvent
// cross-browser event handling for IE5+,  NS6 and Mozilla

{
 if (elm.addEventListener){
   elm.addEventListener(evType, fn, useCapture);
   return true;
 } else if (elm.attachEvent){
   var r = elm.attachEvent("on"+evType, fn);
   return r;
 }
} 
var galleryId='gallery';/*将此更改为库列表的ID*/
var画廊;/*这将是稍后列表的对象引用*/
var galleryImages;/*将包含列表中所有子元素的数组*/
var currentImage;/*跟踪当前应显示的图像*/
var-previousImage;
var预初始化定时器;
preInit();
/*功能*/
函数preInit(){
/*管理最初隐藏图像库列表
甚至在onload被触发之前(此时通常已经太晚了,而且整个列表已经被触发了)
在重新造型之前显示给用户)*/
if((document.getElementById)和&(gallery=document.getElementById(galleryId))){
gallery.style.visibility=“隐藏”;
if(typeof preInitTimer!=“undefined”)clearTimeout(preInitTimer);/*小型Opera修复程序*/
}否则{
preInitTimer=setTimeout(“preInit()”,2);
}
}
功能音量控制器(图像编号、不透明度){
/*帮助器函数专门处理图像和跨浏览器的不透明度处理差异*/
var obj=GalleryImage[图像编号];
if(对象样式){
如果(obj.style.MozOpacity!=null){
/*Mozilla的前CSS3专有规则*/
obj.style.MozOpacity=(不透明度/100)-.001;
}else if(obj.style.opacity!=null){
/*CSS3兼容*/
obj.style.opacity=(不透明度/100)-.001;
}else if(obj.style.filter!=null){
/*IE专有过滤器*/
obj.style.filter=“alpha(不透明度=“+opacity+”)”;
}
}
}
函数fadeInit(){
if(document.getElementById){
preInit();/*应该不是必需的,但IE有时会超越自身并首先触发fadeInit*/
GalleryImage=新阵列;
var节点=gallery.firstChild;
/*而不是使用childNodes(这也会得到空节点,并在以后弄乱脚本)
我们用老式的方式,通过第一个孩子和它的兄弟姐妹循环*/
while(节点){
if(node.nodeType==1){
GalleryImage.push(节点);
}
node=node.nextSibling;
}
对于(i=0;i