Javascript 幻灯片放映速度

Javascript Slideshow Speed

我有此代码和图片幻灯片。我想设置图像修复的时间。 (图像休息 10 分钟,然后淡出)。所有的图像应该休息大约 10 分钟。我喜欢将它用于我公司的 Infoscreen。请帮助:)

(function() {

function Slideshow( element ) {
    this.el = document.querySelector( element );
    this.init();
}

Slideshow.prototype = {
    init: function() {
        this.wrapper = this.el.querySelector( ".slider-wrapper" );
        this.slides = this.el.querySelectorAll( ".slide" );
        this.previous = this.el.querySelector( ".slider-previous" );
        this.next = this.el.querySelector( ".slider-next" );
        this.index = 0;
        this.total = this.slides.length;
        this.timer = null;

        this.action();
        this.stopStart();
    },
    _slideTo: function( slide ) {
        var currentSlide = this.slides[slide];
        currentSlide.style.opacity = 1;

        for( var i = 0; i < this.slides.length; i++ ) {
            var slide = this.slides[i];
            if( slide !== currentSlide ) {
                slide.style.opacity = 0;
            }
        }
    },
    action: function() {
        var self = this;
        self.timer = setInterval(function() {
            self.index++;
            if( self.index == self.slides.length ) {
                self.index = 0;
            }
            self._slideTo( self.index );

        }, 3000);
    },
    stopStart: function() {
        var self = this;
        self.el.addEventListener( "mouseover", function() {
            clearInterval( self.timer );
            self.timer = null;

        }, false);
        self.el.addEventListener( "mouseout", function() {
            self.action();

        }, false);
    }


};

document.addEventListener( "DOMContentLoaded", function() {

    var slider = new Slideshow( "#main-slider" );

});


})();

好吧,只有一个东西可以控制代码中与时间相关的任何事情,所以可以肯定地说这就是您想要更改的东西。

您有一个 setInterval() 正在运行,其时间设置为 3000。将其更改为 600000(10m * 60s * 1000ms),你应该已经准备就绪。

action: function() {
        var self = this;
        self.timer = setInterval(function() {
            self.index++;
            if( self.index == self.slides.length ) {
                self.index = 0;
            }
            self._slideTo( self.index );

        }, 1000*60*10);

此函数使用setInterval,它期望以毫秒为单位的时间间隔作为第二个参数。在此示例中,它设置为 3000,即 3 秒。

改成我上面写的(1000ms是1秒*60=1分钟*10=10分钟)