0

The desired behavior is to click on an image, and have the <div> ease out to full height over 1 second. When the image is clicked again, I need the <div> to ease back in to hidden state in 1 second.

What happens now:

  • Clicking on the image makes the <div> show up immediately, with no transition.
  • Clicking again makes the <div> hide after two seconds. No transition when hiding.

My directive's JS:

.directive('gigDetails', ['$animator', function factory($animator) {
    return {
        restrict: 'A',
        templateUrl: 'partials/gigdetails.html',
        replace: false,
        transclude: false,

        scope: {
            gigId: '@'
        },

        controller: function ($scope) {
            $scope.expandedObjectTracker = {};
        },

        compile: function (tElement, tAttrs) {
            tElement.hide();

            return function link (scope, element, attrs) {
                var animator = $animator(scope, attrs);
                var gigId = scope.gigId;

                var startGigAction = function () {
                    var expandedObject = scope.expandedObjectTracker;
                    if (!expandedObject.openNow) {
                        // not open, open it!
                        animator.show(element);
                        expandedObject.openNow = true;
                    } else {
                        animator.hide(element);
                        expandedObject.openNow = false;
                    }
                };

                element.prev('.gridThumb').on('click', startGigAction);
            }
        },
    };
}]);

Calling it in HTML:

<li ng-repeat="gig in gigs">
    <img ng-src="{{ homeURL + '/' + gig.imgURL }}" class="gridThumb" id="{{ 'gigThumb' + gig.gigId }}">
    <div 
        class="gigDetailsContainer" 
        gig-details 
        gig-id="{{ gig.gigId }}" 
        ng-animate="'gig-container'"
    >
    </div>
</li>

CSS definition:

/* angular transitions */
.gig-container-show, .gig-container-hide {
    -webkit-transition:height 1s ease;
    -moz-transition:height 1s ease;
    -o-transition:height 1s ease;
    transition:height 1s ease;
}

What am I doing wrong?

Aditya M P
  • 5,127
  • 7
  • 41
  • 72
  • Several things is wrong. Give us a Fiddle then we can help better. Try to change your AngularJS version to `1.1.5`. This sintax that you are using is for `1.1.4` and was changed. Your css is too short too, you need at least 2 classes to do the transition. If you want more help, check this site: [NG Animate Sample](http://www.nganimate.org/angularjs/ng-repeat/move) – Bruno Croys Felthes Jul 24 '13 at 19:05
  • Yes, I've finally got it working by changing things around quite a bit. Writing it out as a question really helped ask the right questions. – Aditya M P Jul 24 '13 at 19:18
  • @BrunoCroysFelthes I find however that the "hidden" or "show" state has to be 'reset' with a crude jqLite call because ngAnimate removes the special classes after it is done animating. I wonder if there's a way to clean that up... maybe I'll post it as a separate question. – Aditya M P Jul 24 '13 at 19:20

0 Answers0