wordpress 如何使用php关闭或打开Swiper自动播放并动态更改延迟?当我想创建自定义Elementor小部件时,

d7v8vwbk  于 12个月前  发布在  WordPress
关注(0)|答案(1)|浏览(141)

我尝试动态更改自定义Elementor小部件的swiper slide的自动播放参数。我尝试在swiper类中动态传递字符串作为对象。但它不起作用。

(function($){
    "use strict";

    var WidgetTestimonialCarouselHandler = function ($scope, $) {

        var carousel_elem = $scope.find('.tpc-testimonial-wrapper-ff').eq(0);

            var settings = carousel_elem.data('settings');

            var autoPlay = settings['autoplay'];
            var autoplay_speed = parseInt(settings['autoplay_speed']) || 3000;
            var infiniteLoop = settings['infinite_loop'];
            var display_columns = parseInt(settings['display_columns']) || 2;
            var item_gap = parseInt(settings['item_gap']) || 20;
            
            var auto_Play = autoPlay;
            
            if (autoPlay==true){
                auto_Play = 'autoplay:{delay: '+autoplay_speed+'},'
            }
            else{
                auto_Play = 'autoplay:false,'
            };
           var wc_auto_play = auto_Play.replace(/"/g, '');

            var swiper = new Swiper('.tpc-testimonial-ff', {
                spaceBetween: item_gap,
                slidesPerView: display_columns,
                loop: infiniteLoop,
                wc_auto_play,
            });
        }
    $(window).on('elementor/frontend/init', function () {
        elementorFrontend.hooks.addAction( 'frontend/element_ready/eduhut-testi-addons.default', WidgetTestimonialCarouselHandler);

    });
})(jQuery);

字符串
我想使用elementor的切换按钮关闭或打开自动播放,我还需要更改自动播放的延迟值。但是当我将该参数作为sting传递而不使用qoute时,它不起作用。

r1zhe5dt

r1zhe5dt1#

(function($){
    "use strict";

    var WidgetTestimonialCarouselHandler = function ($scope, $) {

        var carousel_elem = $scope.find('.tpc-testimonial-wrapper-ff').eq(0);

        var settings = carousel_elem.data('settings');

        var autoPlay = settings['autoplay'];
        var autoplay_speed = parseInt(settings['autoplay_speed']) || 3000;
        var infiniteLoop = settings['infinite_loop'];
        var display_columns = parseInt(settings['display_columns']) || 2;
        var item_gap = parseInt(settings['item_gap']) || 20;

        var autoplayOptions = autoPlay ? { delay: autoplay_speed } : false;

        var swiper = new Swiper('.tpc-testimonial-ff', {
            spaceBetween: item_gap,
            slidesPerView: display_columns,
            loop: infiniteLoop,
            autoplay: autoplayOptions,
        });
    }

    $(window).on('elementor/frontend/init', function () {
        elementorFrontend.hooks.addAction('frontend/element_ready/eduhut-testi-addons.default', WidgetTestimonialCarouselHandler);
    });
})(jQuery);

字符串

相关问题