bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

ui bootstrap carousel animation angular 1.2.* issues

Open autumn01 opened this issue 13 years ago • 61 comments

the new implementation of ng-animate seems to be interfering with the animation for the carousel slider directive.

<div ng-class="{
    'active': leaving || (active && !entering),
    'prev': (next || active) && direction=='prev',
    'next': (next || active) && direction=='next',
    'right': direction=='prev',
    'left': direction=='next'
  }" class="item ng-scope ng-isolate-scope ng-animate ng-enter ng-animate-start ng-animate-active ng-enter-active next left" ng-transclude="" ng-repeat="slide in slides" active="slide.active" style="-webkit-transition-property: left, clip; -webkit-transition-duration: 0.6s, 0.6s; ">
...
</div>

note the extra classes. On my end this is causing flickering and

here is a coded example to explain the result http://jsfiddle.net/XxPzW/

I am trying to look into weather there is a way to disable ng-animate for a singe directive, I haven't found anything yet.

EDIT: This account is no longer used i now go by @iamlothian.

EDIT: http://plnkr.co/edit/UWDcnJ2PGZd474D5SuoS?p=preview (work around)

.directive('setNgAnimate', ['$animate', function ($animate) {
    return {
        link: function ($scope, $element, $attrs) {
            $scope.$watch( function() {
                return $scope.$eval($attrs.setNgAnimate, $scope);
            }, function(valnew, valold){
                console.log('Directive animation Enabled: ' + valnew);
                $animate.enabled(!!valnew, $element);
            });
        }
    };
}]);

Used like this:

<div ng-controller="SomeController" set-ng-animate="false">
    <carousel interval="myInterval">
        <slide ng-repeat="slideCollection in groupedSlides" active="slide.active">
            <div>
                <img ng-src="{{slideCollection.image1.image}}" style="margin:auto;">
                <img ng-src="{{slideCollection.image2.image}}" style="margin:auto;">
            </div>
        </slide>
    </carousel>
</div>

autumn01 avatar Nov 19 '13 04:11 autumn01

This will be fixed soon through #1878 .

chrisirhc avatar Mar 19 '14 22:03 chrisirhc

@chrisirhc Thanks. That's good to hear.

@iamlothian Yes, the @autumn01 fix works just fine for now. Thanks very much. For anyone else trying to shortcut this thread and just find the (current) answer: this directive enables/disables ngAnimate for an individual component:

.directive('setNgAnimate', ['$animate', function ($animate) {
    return {
        link: function ($scope, $element, $attrs) {
            $scope.$watch( function() {
                return $scope.$eval($attrs.setNgAnimate, $scope);
            }, function(valnew, valold){
                console.log('Directive animation Enabled: ' + valnew);
                $animate.enabled(!!valnew, $element);
            });
        }
    };
}]);

Used like this:

<div ng-controller="SomeController" set-ng-animate="false">
    <carousel interval="myInterval">
        <slide ng-repeat="slideCollection in groupedSlides" active="slide.active">
            <div>
                <img ng-src="{{slideCollection.image1.image}}" style="margin:auto;">
                <img ng-src="{{slideCollection.image2.image}}" style="margin:auto;">
            </div>
        </slide>
    </carousel>
</div>

fogAndWhisky avatar Mar 19 '14 23:03 fogAndWhisky

Would someone mind testing this out using the snapshot build of AngularJS? There was a change in the class-based animations that removed the blocking feature. This may just fix the problem.

matsko avatar Mar 28 '14 07:03 matsko

http://code.angularjs.org/snapshot/

matsko avatar Mar 28 '14 07:03 matsko

@matsko , looks like you've solved it. Previously, the add animations were blocking each other. Now they're getting applied correctly as the transition only exists when both classes are active (I think).

EDIT: On reading your change further (https://github.com/angular/angular.js/commit/1bebe36aa938890d61188762ed618b1b5e193634), I think it's because it's no longer blocking and waiting for the -add and -remove classes to finish "animating" before addition/removal. Looks good. :+1:

Here are Plunkers with different builds.

Snapshot: http://plnkr.co/edit/cct3xQz0BhqBgirFIs4k?p=preview 1.2.15: http://plnkr.co/edit/hdnP6BOvhvjIrNm3gQUP?p=preview

chrisirhc avatar Mar 28 '14 07:03 chrisirhc

updated my plunk above Still a few issues... I'll have a closer look at this later or early next week.

bealtine avatar Mar 28 '14 11:03 bealtine

I've been holding back my angular-animate to 1.2.8 and this seemed to let ui bootstrap carousel work for a while. (In Firefox, its broken on Chrome though.) I noticed though, even while holding that back to 1.2.8, upgrading the core angular library from 1.2.12 to 1.2.13 breaks the carousel. (I even tried just using angular core 1.2.15 and angular-animate 1.2.15, also broken.)

Been looking at the changes from 1.2.12 to 1.2.13: https://github.com/angular/angular.js/compare/v1.2.12...v1.2.13#files_bucket

linagee avatar Apr 01 '14 15:04 linagee

@linagee more than likely anything < 1.3-beta.4 won't fix the issue since the class-based animation fix was a breaking change. Have a go with the latest 1.3 snapshot.

matsko avatar Apr 01 '14 15:04 matsko

matsko: I can verify that 1.3.0-beta-4 looks a lot more better than 1.2.15! Thanks.

linagee avatar Apr 01 '14 16:04 linagee

To remove ngAnimate from a single directive, do as described here:

https://github.com/angular-ui/bootstrap/issues/1350#issuecomment-34595075

leniel avatar May 20 '14 20:05 leniel

@leniel that issues is a duplication of this thread, and that solution was first proposed here 6 months ago.

iamlothian avatar May 20 '14 22:05 iamlothian

@iamlothian Oh yes... TLDR; :smile: So that should be marked as duplicate, shouldn't it?

leniel avatar May 20 '14 22:05 leniel

Hey guys. Is there anything else here that needs fixing in regards to ngAnimate?

matsko avatar May 22 '14 15:05 matsko

@matsko thnx for keeping an eye on this one, much appreciated! For the moment I'm not sure what the problem is, I really haven't had too much time to spend on the carousel thing lately... But seems like recurring problem so let me have a closer look over the weekend.

pkozlowski-opensource avatar May 22 '14 17:05 pkozlowski-opensource

@matsko @pkozlowski-opensource Here is an updated plunker using the latest versions: Angular "1.3.0-beta.5" and UI "0.11.0"

http://plnkr.co/edit/bY9nZIqvIkL4XybMe354?p=preview

It looks like the directive still fails to function normally without disabling angular animation an the element. I had to do this manually though as enabling it agin after the initial load using $animate.enabled(true, $element); doesn't work now.

Any ideas.

EDIT Via @leniel: updated bootstrap ui version to 0.11.0

iamlothian avatar May 22 '14 23:05 iamlothian

@iamlothian isn't the latest version 0.11.0? http://angular-ui.github.io/bootstrap/

leniel avatar May 22 '14 23:05 leniel

I just ran into this, too. https://github.com/angular-ui/bootstrap/issues/1350#issuecomment-34595075 provided a satisfactory workaround.

whitehat101 avatar May 29 '14 06:05 whitehat101

not sure if this is still live or not but the problem still exists with 1.3.0-beta.17 : http://plnkr.co/edit/DCzZ07jQxNO4GfqTf3aO?p=preview

Thanks...

bealtine avatar Jul 26 '14 23:07 bealtine

Problem still exists. The height of the images is smaller then originally and the carousel slide distorts the images also...

YoavGrosman avatar Jul 29 '14 02:07 YoavGrosman

problem still exists with all latests

onemenny avatar Nov 23 '14 20:11 onemenny