cSlider: stop autoplay on mouseover

前端 未结 1 1634
灰色年华
灰色年华 2021-01-06 01:33

How can I stop the autoplay function of cSlider with an onmouseover event?

HTML:

1条回答
  •  难免孤独
    2021-01-06 01:59

    This feature not implemented by default but this shouldn't stop you from implementing it on your own. Look at modified plugin code below (draw attention on stop and 'start' methods)

    (function ($, undefined) {
    
        /*
        * Slider object.
        */
        $.Slider = function (options, element) {
    
            this.$el = $(element);
    
            this._init(options);
    
        };
    
        $.Slider.defaults = {
            current: 0,     // index of current slide
            bgincrement: 50, // increment the bg position (parallax effect) when sliding
            autoplay: false, // slideshow on / off
            interval: 4000  // time between transitions
        };
    
        $.Slider.prototype = {
            _init: function (options) {
    
                this.options = $.extend(true, {}, $.Slider.defaults, options);
    
                this.$slides = this.$el.children('div.da-slide');
                this.slidesCount = this.$slides.length;
    
                this.current = this.options.current;
    
                if (this.current < 0 || this.current >= this.slidesCount) {
    
                    this.current = 0;
    
                }
    
                this.$slides.eq(this.current).addClass('da-slide-current');
    
                var $navigation = $('

    With updated plugin you can pause and renew autiplaying with this code:

    $('#da-slider').hover(
        function () {
            $(this).cslider("stop");
        },
        function () {
            $(this).cslider("start");
        }
    );
    

    0 讨论(0)
提交回复
热议问题