Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 幻灯片上每个图像的不同链接_Javascript_Html - Fatal编程技术网

Javascript 幻灯片上每个图像的不同链接

Javascript 幻灯片上每个图像的不同链接,javascript,html,Javascript,Html,我有一个用于幻灯片的javascript,我希望幻灯片上的每个图像都有不同的链接。我刚刚为每一个添加了href标记,但它不起作用。。。以下是脚本: window.addEventListener('load', slideShow, false); function slideShow() { var globals = { slideDelay: 4000, fadeDelay: 35, wrapperID: "slideShowIm

我有一个用于幻灯片的javascript,我希望幻灯片上的每个图像都有不同的链接。我刚刚为每一个添加了href标记,但它不起作用。。。以下是脚本:

window.addEventListener('load', slideShow, false);

function slideShow() {

    var globals = {
        slideDelay: 4000,
        fadeDelay: 35,
        wrapperID: "slideShowImages",
        buttonID: "slideShowButton",
        buttonStartText: "Start Slides",
        buttonStopText: "Stop Slides",
        buttonObject: null,
        slideImages: [],
        slideShowID: null,
        slideShowRunning: true,
        slideIndex: 0
    }

    initializeGlobals();

    if (insufficientSlideShowMarkup()) {
        return;
    }

    if (globals.slideImages.length == 1) {
        return;
    }

    initializeSlideShowMarkup();

    globals.wrapperObject.addEventListener('click', toggleSlideShow, false);

    if (globals.buttonObject) {
        globals.buttonObject.addEventListener('click', toggleSlideShow, false);
    }

    startSlideShow();


    function initializeGlobals() {
        globals.wrapperObject = (document.getElementById(globals.wrapperID) ? document.getElementById(globals.wrapperID) : null);
        globals.buttonObject = (document.getElementById(globals.buttonID) ? document.getElementById(globals.buttonID) : null);

        if (globals.wrapperObject) {
            globals.slideImages = (globals.wrapperObject.querySelectorAll('img') ? globals.wrapperObject.querySelectorAll('img') : []);
        }
    }

    function insufficientSlideShowMarkup() {
        if (!globals.wrapperObject) {
            if (globals.buttonObject) {
                globals.buttonObject.style.display = "none";
            }
            return true;
        }

        if (!globals.slideImages.length) {
            if (globals.wrapperObject) {
                globals.wrapperObject.style.display = "none";
            }

            if (globals.buttonObject) {
                globals.buttonObject.style.display = "none";
            }

            return true;
        }

        return false;
    }

    function initializeSlideShowMarkup() {
        var slideWidthMax = maxSlideWidth();
        var slideHeightMax = maxSlideHeight();

        globals.wrapperObject.style.position = "relative";
        globals.wrapperObject.style.overflow = "hidden";
        globals.wrapperObject.style.width = slideWidthMax + "px";
        globals.wrapperObject.style.height = slideHeightMax + "px";

        var slideCount = globals.slideImages.length;
        for (var i = 0; i < slideCount; i++) {
            globals.slideImages[i].style.opacity = 0;
            globals.slideImages[i].style.position = "absolute";
            globals.slideImages[i].style.top = (slideHeightMax - globals.slideImages[i].getBoundingClientRect().height) / 2 + "px";
            globals.slideImages[i].style.left = (slideWidthMax - globals.slideImages[i].getBoundingClientRect().width) / 2 + "px";
        }

        globals.slideImages[0].style.opacity = 1;

        if (globals.buttonObject) {
            globals.buttonObject.textContent = globals.buttonStopText;
        }
    }

    function maxSlideWidth() {
        var maxWidth = 0;
        var maxSlideIndex = 0;
        var slideCount = globals.slideImages.length;

        for (var i = 0; i < slideCount; i++) {
            if (globals.slideImages[i].width > maxWidth) {
                maxWidth = globals.slideImages[i].width;
                maxSlideIndex = i;
            }
        }

        return globals.slideImages[maxSlideIndex].getBoundingClientRect().width;
    }

    function maxSlideHeight() {
        var maxHeight = 0;
        var maxSlideIndex = 0;
        var slideCount = globals.slideImages.length;

        for (var i = 0; i < slideCount; i++) {
            if (globals.slideImages[i].height > maxHeight) {
                maxHeight = globals.slideImages[i].height;
                maxSlideIndex = i;
            }
        }

        return globals.slideImages[maxSlideIndex].getBoundingClientRect().height;
    }

    function startSlideShow() {
        globals.slideShowID = setInterval(transitionSlides, globals.slideDelay);
    }

    function haltSlideShow() {
        clearInterval(globals.slideShowID);
    }

    function toggleSlideShow() {
        if (globals.slideShowRunning) {
            haltSlideShow();
            if (globals.buttonObject) {
                globals.buttonObject.textContent = globals.buttonStartText;
            }
        } else {
            startSlideShow();
            if (globals.buttonObject) {
                globals.buttonObject.textContent = globals.buttonStopText;
            }
        }
        globals.slideShowRunning = !(globals.slideShowRunning);
    }

    function transitionSlides() {
        var currentSlide = globals.slideImages[globals.slideIndex];

        ++(globals.slideIndex);
        if (globals.slideIndex >= globals.slideImages.length) {
            globals.slideIndex = 0;
        }

        var nextSlide = globals.slideImages[globals.slideIndex];

        var currentSlideOpacity = 1;
        var nextSlideOpacity = 0;.
        var opacityLevelIncrement = 1 / globals.fadeDelay;
        var fadeActiveSlidesID = setInterval(fadeActiveSlides, globals.fadeDelay);

        function fadeActiveSlides() {
            currentSlideOpacity -= opacityLevelIncrement;
            nextSlideOpacity += opacityLevelIncrement;

            if (currentSlideOpacity >= 0 && nextSlideOpacity <= 1) {
                currentSlide.style.opacity = currentSlideOpacity;
                nextSlide.style.opacity = nextSlideOpacity;
            } else {
                currentSlide.style.opacity = 0;
                nextSlide.style.opacity = 1;
                clearInterval(fadeActiveSlidesID);
            }
        }
    }
}
window.addEventListener('load',slideShow,false);
函数幻灯片(){
变量全局={
幻灯片播放:4000,
法德雷:35,
wrapperID:“幻灯片放映图像”,
buttonID:“幻灯片显示按钮”,
buttonStartText:“开始幻灯片”,
按钮选择文字:“停止幻灯片”,
buttonObject:null,
幻灯片图像:[],
slideShowID:null,
幻灯片:对,
幻灯片索引:0
}
初始化全局();
if(不足的SlideshowMarkup()){
返回;
}
if(globals.slidemages.length==1){
返回;
}
初始化SlideShowMarkup();
globals.wrapperObject.addEventListener('click',toggleSlideShow,false);
if(全局按钮对象){
globals.buttonObject.addEventListener('click',toggleSlideShow,false);
}
startSlideShow();
函数initializeGlobals(){
globals.wrapperObject=(document.getElementById(globals.wrapperID)?document.getElementById(globals.wrapperID):null);
globals.buttonObject=(document.getElementById(globals.buttonID)?document.getElementById(globals.buttonID):null);
if(globals.wrapperObject){
globals.slidemages=(globals.wrapperObject.queryselectoral('img')?globals.wrapperObject.queryselectoral('img'):[]);
}
}
函数不足SlideshowMarkup(){
如果(!globals.wrapperObject){
if(全局按钮对象){
globals.buttonObject.style.display=“无”;
}
返回true;
}
if(!globals.slideImages.length){
if(globals.wrapperObject){
globals.wrapperObject.style.display=“无”;
}
if(全局按钮对象){
globals.buttonObject.style.display=“无”;
}
返回true;
}
返回false;
}
函数初始化SlideShowMarkup(){
var slideWidthMax=maxSlideWidth();
var slideHeightMax=maxlideheight();
globals.wrapperObject.style.position=“relative”;
globals.wrapperObject.style.overflow=“隐藏”;
globals.wrapperObject.style.width=slideWidthMax+“px”;
globals.wrapperObject.style.height=slideHeightMax+“px”;
var slideCount=globals.slidemages.length;
对于(变量i=0;imaxWidth){
maxWidth=globals.slideImages[i]。宽度;
maxSlideIndex=i;
}
}
返回globals.slideImages[maxSlideIndex].getBoundingClientRect().width;
}
函数MaxSlideHight(){
var maxHeight=0;
var maxSlideIndex=0;
var slideCount=globals.slidemages.length;
对于(变量i=0;imaxHeight){
maxHeight=globals.slideImages[i]。高度;
maxSlideIndex=i;
}
}
返回globals.slideImages[maxSlideIndex].getBoundingClientRect().height;
}
函数startSlideShow(){
globals.slideShowID=setInterval(transitionSlides,globals.slidelay);
}
函数haltSlideShow(){
clearInterval(globals.slideShowID);
}
函数toggleSlideShow(){
if(全局。幻灯片放映){
haltSlideShow();
if(全局按钮对象){
globals.buttonObject.textContent=globals.buttonStarText;
}
}否则{
startSlideShow();
if(全局按钮对象){
globals.buttonObject.textContent=globals.buttonoptext;
}
}
globals.slideShowRunning=!(globals.slideShowRunning);
}
函数转换滑块(){
var currentSlide=globals.slideImages[globals.slideIndex];
++(globals.slideIndex);
if(globals.slideIndex>=globals.slideImages.length){
globals.slideIndex=0;
}
var nextSlide=globals.slideImages[globals.slideIndex];
var CurrentSlidePocity=1;
var nextSlideOpacity=0;。
var opacityLevelIncrement=1/globals.fadeDelay;
var fadeActiveSlidesID=setInterval(fadeActiveSlides,globals.fadeDelay);
函数fadeActiveSlides(){
CurrentSlidePocity-=opacityLevel增量;
nextSlideOpacity+=不透明级别增量;

如果(CurrentSlidePocity>=0&&nextSlideOpacityarry=[link1,link1,link1,link1]


创建锚点并遍历数组,为href属性指定所需数组元素的值,然后插入幻灯片

“我刚刚添加了href标记”Where?我看不到它。我在html上做了,js在另一个文件上。我在哪里做?