简体   繁体   English

有没有办法动态改变离子滑动盒滑动间隔值?

[英]Is there a way to dynamically change ion-slide box slide-interval value?

I have been struggling with this for days now, I'll appreciate your help. 我几天来一直在努力,我会感激你的帮助。

I have a directive where there's an ads slide which slide-interval is tied to a var in the scope and I'm trying to change how long each one of them stays active in the slideChanged function by updating that variable, next line of code is to reload the ionicSlideBoxDeletegate, however, it's not speeding up the animation at all. 我有一个指令,其中有一个广告幻灯片,其中slide-interval与范围中的var绑定,我试图通过更新该变量来改变每个人在slideChanged函数中保持活动的时间,下一行代码是然而,重新加载ionicSlideBoxDeletegate,它根本不会加速动画。 Here's the code... 这是代码......

.directive('adDirective', function( $ionicSlideBoxDelegate ){
    return {
        restrict: "E",
        replace: true,
        template: ( '<div class="absolute promo-banner-wrp">'
                    + '<ion-slide-box ng-init="disableSwipe()" auto-play="true" on-slide-changed="slideChanged(index)" show-pager="false" does-continue="true" slide-interval="{{speed}}" ng-if="ads.length">'
                        + '<ion-slide ng-click="adTap(ad)" ng-repeat="ad in ads">'
                            + '<img ng-src="{{ad.src}}" />'
                        + '</ion-slide>'
                    + '</ion-slide-box></div>' ),
        controller: function($scope) {
            $scope.slideChanged = function ( index ) {
                $scope.speed = parseInt( $scope.ads[index].category + '000' );
                $ionicSlideBoxDelegate.update();
            };
            $scope.speed = 2000;//In miliseconds
        }
    }
})

I think in order to do what you're asking you'd have to modify ionic.bundle.js as I'm not sure this is supported. 我认为为了做你所要求的,你必须修改ionic.bundle.js,因为我不确定这是否支持。 Instead, you could just turn off autoplay and manage the looping yourself: 相反,您可以关闭自动播放并自行管理循环:

var nextSlide = function(){
    $ionicSlideBoxDelegate.$getByHandle(YOUR_DELEGATE_HANDLE).next(ANIMATION_SPEED);
    setTimeout(nextSlide, YOUR_SLIDE_INTERVAL);
}
nextSlide();

You might also want to catch users changing slides themselves and reset your timeout function. 您可能还希望捕获用户自己更改幻灯片并重置超时功能。

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

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