首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使这个滑块在最后的滑梯停止?

如何使这个滑块在最后的滑梯停止?
EN

Stack Overflow用户
提问于 2014-05-01 18:54:04
回答 1查看 92关注 0票数 0

我有一个旋转木马文本自动播放不停止。有什么办法能让它在最后一刻停止吗?这是代码http://codepen.io/anon/pen/kyiqn

代码语言:javascript
复制
(function () {
    rt.Homepage = function () {
        function e() {
            var e = this;
            this.currentCaption = 0, this.$carousel = $(".js-carousel"), this.$captions = $(".js-captions"), this.switchCaption(1), setInterval(function () {
                return e.advanceCaption()
            }, 2000), this.addHandlers()
        }
        return e.prototype.addHandlers = function () {}, 

        e.prototype.advanceCaption = function () {
            var e, t;
            return this.currentCaption++, t = 20, e = this.currentCaption % t + 1, this.switchCaption(e)
        }, e.prototype.switchCaption = function (e) {
            var t, n, r, i, s, o, u = this;
            n = "state-1 state-2 state-3 state-4 state-5 state-6 state-7 state-8 state-9 state-10 state-11 state-12 state-13 state-14 state-15 state-16 state-17 state-18 state-19 state-20", this.$carousel.removeClass(n).addClass("state-" + e), o = this.$captions;
            for (i = 0, s = o.length; i < s; i++) t = o[i], r = $(".caption-" + e, t).width(), $(t).width(r);
            return _.delay(function () {
                return u.$carousel.addClass("show-caption")
            }, 500)
        }, e
    }(), $(function () {
        return new rt.Homepage
    })
}).call(this);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-01 19:24:21

我编辑了它来做您想做的事情,并且使javascript (稍微)更清晰,这样您就可以看到正在发生的事情。如果您有非最小化的javascript,我建议您做类似的编辑。

CodePen

代码语言:javascript
复制
(function () {
    rt.Homepage = function () {
        function e() {
            var e = this;
            this.currentCaption = 0;
            this.$carousel = $(".js-carousel");
            this.$captions = $(".js-captions");
            this.switchCaption(1);

            // set a variable for the interval, so we can stop it later
            this.interval = setInterval(function () {
                return e.advanceCaption()
            }, 1500);

            this.addHandlers();
        }

        e.prototype.addHandlers = function () {}

        e.prototype.advanceCaption = function () {
            this.currentCaption++;

            // if currentCaption reaches final caption, stop the interval
            if (this.currentCaption >= 4) {
                clearInterval(this.interval)
            }

            return this.switchCaption(this.currentCaption + 1);
        }

        e.prototype.switchCaption = function (e) {
            var t, n, r, i, s, o, u = this;
            n = "state-1 state-2 state-3 state-4 state-5";
            this.$carousel.removeClass(n).addClass("state-" + e);
            o = this.$captions;
            for (i = 0, s = o.length; i < s; i++) t = o[i];
            r = $(".caption-" + e, t).width(), $(t).width(r);
            return _.delay(function () {
                return u.$carousel.addClass("show-caption")
            }, 500)
        }

        return e;
    }(), $(function () {
        return new rt.Homepage
    })
}).call(this);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23414497

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档