简体   繁体   English

具有多个图像且没有重复的自动滑块

[英]Automatic slider with multiple images and no duplicates

I need to make two separate slideshows which automatically changes images with no controls whatsoever, but there should not be the same images in both the slideshows at the same time. 我需要制作两个单独的幻灯片,这些幻灯片可以自动更改图像而无任何控件,但是两个幻灯片中不应同时显示相同的图像。 I added a small function to check for this, and if both images were the same, I traversed my order by 1. But, unfortunately my function is not running all the time, but only after the first image is selected and if it does not match the image in the second image, it does not do anything. 我添加了一个小函数进行检查,如果两个图像都相同,我将顺序遍历了1。但是,不幸的是,我的函数并非一直运行,而是仅在选择了第一个图像之后才运行匹配第二张图片中的图片,它不会执行任何操作。 I need my function to run whenever the images presently shown matches with each other, and if it does change one of the image. 每当当前显示的图像相互匹配,并且确实改变了其中一张图像时,我都需要运行我的函数。 Here is my simple code: 这是我的简单代码:

[https://jsfiddle.net/dfv32vfq/]

use this code it must better. 使用此代码必须更好。

function showSlides() {
    var i;
    var slides = document.getElementsByClassName("mySlides");

    for (i = 0; i < slides.length; i++) {
       slides[i].style.display = "none";
    }

    do
    {

        slideIndex++;
        if (slideIndex> slides.length) {slideIndex = 1}
    }
    while ($('.mySlides img').attr('src') == $('.mySlides1 img').attr('src'));

    slides[slideIndex-1].style.display = "block";

    setTimeout(showSlides, 2000); // Change image every 2 seconds
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM