目录搜索
AngularJS API Referenceautoauto/serviceauto/service/$injectorauto/service/$providengng/directiveng/directive/ang/directive/formng/directive/inputng/directive/input[checkbox]ng/directive/input[date]ng/directive/input[dateTimeLocal]ng/directive/input[email]ng/directive/input[month]ng/directive/input[number]ng/directive/input[radio]ng/directive/input[text]ng/directive/input[time]ng/directive/input[url]ng/directive/input[week]ng/directive/ngAppng/directive/ngBindng/directive/ngBindHtmlng/directive/ngBindTemplateng/directive/ngBlurng/directive/ngChangeng/directive/ngCheckedng/directive/ngClassng/directive/ngClassEvenng/directive/ngClassOddng/directive/ngClickng/directive/ngCloakng/directive/ngControllerng/directive/ngCopyng/directive/ngCspng/directive/ngCutng/directive/ngDblclickng/directive/ngDisabledng/directive/ngFocusng/directive/ngFormng/directive/ngHideng/directive/ngHrefng/directive/ngIfng/directive/ngIncludeng/directive/ngInitng/directive/ngKeydownng/directive/ngKeypressng/directive/ngKeyupng/directive/ngListng/directive/ngModelng/directive/ngModelOptionsng/directive/ngMousedownng/directive/ngMouseenterng/directive/ngMouseleaveng/directive/ngMousemoveng/directive/ngMouseoverng/directive/ngMouseupng/directive/ngNonBindableng/directive/ngOpenng/directive/ngPasteng/directive/ngPluralizeng/directive/ngReadonlyng/directive/ngRepeatng/directive/ngSelectedng/directive/ngShowng/directive/ngSrcng/directive/ngSrcsetng/directive/ngStyleng/directive/ngSubmitng/directive/ngSwitchng/directive/ngTranscludeng/directive/ngValueng/directive/scriptng/directive/selectng/directive/textareang/filterng/filter/currencyng/filter/dateng/filter/filterng/filter/jsonng/filter/limitTong/filter/lowercaseng/filter/numberng/filter/orderByng/filter/uppercaseng/functionng/function/angular.bindng/function/angular.bootstrapng/function/angular.copyng/function/angular.elementng/function/angular.equalsng/function/angular.extendng/function/angular.forEachng/function/angular.fromJsonng/function/angular.identityng/function/angular.injectorng/function/angular.isArrayng/function/angular.isDateng/function/angular.isDefinedng/function/angular.isElementng/function/angular.isFunctionng/function/angular.isNumberng/function/angular.isObjectng/function/angular.isStringng/function/angular.isUndefinedng/function/angular.lowercaseng/function/angular.moduleng/function/angular.noopng/function/angular.toJsonng/function/angular.uppercaseng/objectng/object/angular.versionng/providerng/provider/$animateProviderng/provider/$compileProviderng/provider/$controllerProviderng/provider/$filterProviderng/provider/$httpProviderng/provider/$interpolateProviderng/provider/$locationProviderng/provider/$logProviderng/provider/$parseProviderng/provider/$rootScopeProviderng/provider/$sceDelegateProviderng/provider/$sceProviderng/serviceng/service/$anchorScrollng/service/$animateng/service/$cacheFactoryng/service/$compileng/service/$controllerng/service/$documentng/service/$exceptionHandlerng/service/$filterng/service/$httpng/service/$httpBackendng/service/$interpolateng/service/$intervalng/service/$localeng/service/$locationng/service/$logng/service/$parseng/service/$qng/service/$rootElementng/service/$rootScopeng/service/$sceng/service/$sceDelegateng/service/$templateCacheng/service/$timeoutng/service/$windowng/typeng/type/$cacheFactory.Cacheng/type/$compile.directive.Attributesng/type/$rootScope.Scopeng/type/angular.Moduleng/type/form.FormControllerng/type/ngModel.NgModelControllerngAnimatengAnimate/providerngAnimate/provider/$animateProviderngAnimate/servicengAnimate/service/$animatengCookiesngCookies/servicengCookies/service/$cookiesngCookies/service/$cookieStorengMessagesngMessages/directivengMessages/directive/ngMessagengMessages/directive/ngMessagesngMockngMock/functionngMock/function/angular.mock.dumpngMock/function/angular.mock.injectngMock/function/angular.mock.modulengMock/objectngMock/object/angular.mockngMock/providerngMock/provider/$exceptionHandlerProviderngMock/servicengMock/service/$exceptionHandlerngMock/service/$httpBackendngMock/service/$intervalngMock/service/$logngMock/service/$timeoutngMock/typengMock/type/angular.mock.TzDatengMockE2EngMockE2E/servicengMockE2E/service/$httpBackendngResourcengResource/servicengResource/service/$resourcengRoutengRoute/directivengRoute/directive/ngViewngRoute/providerngRoute/provider/$routeProviderngRoute/servicengRoute/service/$routengRoute/service/$routeParamsngSanitizengSanitize/filterngSanitize/filter/linkyngSanitize/servicengSanitize/service/$sanitizengTouchngTouch/directivengTouch/directive/ngClickngTouch/directive/ngSwipeLeftngTouch/directive/ngSwipeRightngTouch/servicengTouch/service/$swipe
文字

AngularJS: API: ngAnimate/service/$animate


$animate

  1. - $animateProvider
  2. - service in module ngAnimate

The $animate service provides animation detection support while performing DOM operations (enter, leave and move) as well as during addClass and removeClass operations. When any of these operations are run, the $animate service will examine any JavaScript-defined animations (which are defined by using the $animateProvider provider object) as well as any CSS-defined animations against the CSS classes present on the element once the DOM operation is run.

The $animate service is used behind the scenes with pre-existing directives and animation with these directives will work out of the box without any extra configuration.

Requires the ngAnimate module to be installed.

Please visit the ngAnimate module overview page learn more about how to use animations in your application.

用法

$animate();

方法

  • enter(element, parentElement, afterElement, [doneCallback]);

    Appends the element to the parentElement element that resides in the document and then runs the enter animation. Once the animation is started, the following CSS classes will be present on the element for the duration of the animation:

    Below is a breakdown of each step that occurs during enter animation:

    动画步骤 元素的class属性看上去像
    1. $animate.enter(...) is called class="my-animation"
    2. element is inserted into the parentElement element or beside the afterElement element class="my-animation"
    3. $animate waits for the next digest to start the animation class="my-animation ng-animate"
    4. $animate runs the JavaScript-defined animations detected on the element class="my-animation ng-animate"
    5. the .ng-enter class is added to the element class="my-animation ng-animate ng-enter"
    6. $animate scans the element styles to get the CSS transition/animation duration and delay class="my-animation ng-animate ng-enter"
    7. $animate blocks all CSS transitions on the element to ensure the .ng-enter class styling is applied right away class="my-animation ng-animate ng-enter"
    8. $animate waits for a single animation frame (this performs a reflow) class="my-animation ng-animate ng-enter"
    9. $animate removes the CSS transition block placed on the element class="my-animation ng-animate ng-enter"
    10. the .ng-enter-active class is added (this triggers the CSS transition/animation) class="my-animation ng-animate ng-enter ng-enter-active"
    11. $animate waits for the animation to complete (via events and timeout) class="my-animation ng-animate ng-enter ng-enter-active"
    12. The animation ends and all generated CSS classes are removed from the element class="my-animation"
    13. The doneCallback() callback is fired (if provided) class="my-animation"

    参数

    参数 类型 详述
    element DOMElement

    the element that will be the focus of the enter animation

    parentElement DOMElement

    the parent element of the element that will be the focus of the enter animation

    afterElement DOMElement

    the sibling element (which is the previous element) of the element that will be the focus of the enter animation

    doneCallback
    (可选)
    function()=

    the callback function that will be called once the animation is complete

    返回值

    Function

    the animation cancellation function

  • leave(element, [doneCallback]);

    Runs the leave animation operation and, upon completion, removes the element from the DOM. Once the animation is started, the following CSS classes will be added for the duration of the animation:

    Below is a breakdown of each step that occurs during leave animation:

    动画步骤 元素的class属性看上去像
    1. $animate.leave(...) is called class="my-animation"
    2. $animate runs the JavaScript-defined animations detected on the element class="my-animation ng-animate"
    3. $animate waits for the next digest to start the animation class="my-animation ng-animate"
    4. the .ng-leave class is added to the element class="my-animation ng-animate ng-leave"
    5. $animate scans the element styles to get the CSS transition/animation duration and delay class="my-animation ng-animate ng-leave"
    6. $animate blocks all CSS transitions on the element to ensure the .ng-leave class styling is applied right away class="my-animation ng-animate ng-leave”
    7. $animate waits for a single animation frame (this performs a reflow) class="my-animation ng-animate ng-leave"
    8. $animate removes the CSS transition block placed on the element class="my-animation ng-animate ng-leave”
    9. the .ng-leave-active class is added (this triggers the CSS transition/animation) class="my-animation ng-animate ng-leave ng-leave-active"
    10. $animate waits for the animation to complete (via events and timeout) class="my-animation ng-animate ng-leave ng-leave-active"
    11. The animation ends and all generated CSS classes are removed from the element class="my-animation"
    12. The element is removed from the DOM ...
    13. The doneCallback() callback is fired (if provided) ...

    参数

    参数 类型 详述
    element DOMElement

    the element that will be the focus of the leave animation

    doneCallback
    (可选)
    function()=

    the callback function that will be called once the animation is complete

    返回值

    Function

    the animation cancellation function

  • move(element, parentElement, afterElement, [doneCallback]);

    Fires the move DOM operation. Just before the animation starts, the animate service will either append it into the parentElement container or add the element directly after the afterElement element if present. Then the move animation will be run. Once the animation is started, the following CSS classes will be added for the duration of the animation:

    Below is a breakdown of each step that occurs during move animation:

    动画步骤 元素的class属性看上去像
    1. $animate.move(...) is called class="my-animation"
    2. element is moved into the parentElement element or beside the afterElement element class="my-animation"
    3. $animate waits for the next digest to start the animation class="my-animation ng-animate"
    4. $animate runs the JavaScript-defined animations detected on the element class="my-animation ng-animate"
    5. the .ng-move class is added to the element class="my-animation ng-animate ng-move"
    6. $animate scans the element styles to get the CSS transition/animation duration and delay class="my-animation ng-animate ng-move"
    7. $animate blocks all CSS transitions on the element to ensure the .ng-move class styling is applied right away class="my-animation ng-animate ng-move”
    8. $animate waits for a single animation frame (this performs a reflow) class="my-animation ng-animate ng-move"
    9. $animate removes the CSS transition block placed on the element class="my-animation ng-animate ng-move”
    10. the .ng-move-active class is added (this triggers the CSS transition/animation) class="my-animation ng-animate ng-move ng-move-active"
    11. $animate waits for the animation to complete (via events and timeout) class="my-animation ng-animate ng-move ng-move-active"
    12. The animation ends and all generated CSS classes are removed from the element class="my-animation"
    13. The doneCallback() callback is fired (if provided) class="my-animation"

    参数

    参数 类型 详述
    element DOMElement

    the element that will be the focus of the move animation

    parentElement DOMElement

    the parentElement element of the element that will be the focus of the move animation

    afterElement DOMElement

    the sibling element (which is the previous element) of the element that will be the focus of the move animation

    doneCallback
    (可选)
    function()=

    the callback function that will be called once the animation is complete

    返回值

    Function

    the animation cancellation function

  • addClass(element, className, [doneCallback]);

    Triggers a custom animation event based off the className variable and then attaches the className value to the element as a CSS class. Unlike the other animation methods, the animate service will suffix the className value with -add in order to provide the animate service the setup and active CSS classes in order to trigger the animation (this will be skipped if no CSS transitions or keyframes are defined on the -add-active or base CSS class).

    Below is a breakdown of each step that occurs during addClass animation:

    动画步骤 元素的class属性看上去像
    1. $animate.addClass(element, 'super') is called class="my-animation"
    2. $animate runs the JavaScript-defined animations detected on the element class="my-animation ng-animate"
    3. the .super-add class is added to the element class="my-animation ng-animate super-add"
    4. $animate waits for a single animation frame (this performs a reflow) class="my-animation ng-animate super-add"
    5. the .super and .super-add-active classes are added (this triggers the CSS transition/animation) class="my-animation ng-animate super super-add super-add-active"
    6. $animate scans the element styles to get the CSS transition/animation duration and delay class="my-animation ng-animate super-add"
    7. $animate waits for the animation to complete (via events and timeout) class="my-animation super super-add super-add-active"
    8. The animation ends and all generated CSS classes are removed from the element class="my-animation super"
    9. The super class is kept on the element class="my-animation super"
    10. The doneCallback() callback is fired (if provided) class="my-animation super"

    参数

    参数 类型 详述
    element DOMElement

    the element that will be animated

    className string

    the CSS class that will be added to the element and then animated

    doneCallback
    (可选)
    function()=

    the callback function that will be called once the animation is complete

    返回值

    Function

    the animation cancellation function

  • removeClass(element, className, [doneCallback]);

    Triggers a custom animation event based off the className variable and then removes the CSS class provided by the className value from the element. Unlike the other animation methods, the animate service will suffix the className value with -remove in order to provide the animate service the setup and active CSS classes in order to trigger the animation (this will be skipped if no CSS transitions or keyframes are defined on the -remove or base CSS classes).

    Below is a breakdown of each step that occurs during removeClass animation:

    动画步骤 元素的class属性看上去像
    1. $animate.removeClass(element, 'super') is called class="my-animation super"
    2. $animate runs the JavaScript-defined animations detected on the element class="my-animation super ng-animate"
    3. the .super-remove class is added to the element class="my-animation super ng-animate super-remove"
    4. $animate waits for a single animation frame (this performs a reflow) class="my-animation super ng-animate super-remove"
    5. the .super-remove-active classes are added and .super is removed (this triggers the CSS transition/animation) class="my-animation ng-animate super-remove super-remove-active"
    6. $animate scans the element styles to get the CSS transition/animation duration and delay class="my-animation super ng-animate super-remove"
    7. $animate waits for the animation to complete (via events and timeout) class="my-animation ng-animate super-remove super-remove-active"
    8. The animation ends and all generated CSS classes are removed from the element class="my-animation"
    9. The doneCallback() callback is fired (if provided) class="my-animation"

    参数

    参数 类型 详述
    element DOMElement

    the element that will be animated

    className string

    the CSS class that will be animated and then removed from the element

    doneCallback
    (可选)
    function()=

    the callback function that will be called once the animation is complete

    返回值

    Function

    the animation cancellation function

  • setClass(element, add, remove, [done]);

    Adds and/or removes the given CSS classes to and from the element. Once complete, the done() callback will be fired (if provided).

    动画步骤 元素的class属性看上去像
    1. $animate.removeClass(element, ‘on’, ‘off’) is called class="my-animation super off”
    2. $animate runs the JavaScript-defined animations detected on the element class="my-animation super ng-animate off”
    3. the .on-add and .off-remove classes are added to the element class="my-animation ng-animate on-add off-remove off”
    4. $animate waits for a single animation frame (this performs a reflow) class="my-animation ng-animate on-add off-remove off”
    5. the .on, .on-add-active and .off-remove-active classes are added and .off is removed (this triggers the CSS transition/animation) class="my-animation ng-animate on on-add on-add-active off-remove off-remove-active”
    6. $animate scans the element styles to get the CSS transition/animation duration and delay class="my-animation ng-animate on on-add on-add-active off-remove off-remove-active"
    7. $animate waits for the animation to complete (via events and timeout) class="my-animation ng-animate on on-add on-add-active off-remove off-remove-active"
    8. The animation ends and all generated CSS classes are removed from the element class="my-animation"
    9. The doneCallback() callback is fired (if provided) class="my-animation"

    参数

    参数 类型 详述
    element DOMElement

    the element which will have its CSS classes changed removed from it

    add string

    the CSS classes which will be added to the element

    remove string

    the CSS class which will be removed from the element

    done
    (可选)
    function=

    the callback function (if provided) that will be fired after the CSS classes have been set on the element

    返回值

    Function

    the animation cancellation function

  • enabled([value], [element]);

    Globally enables/disables animations.

    参数

    参数 类型 详述
    value
    (可选)
    boolean

    If provided then set the animation on or off.

    element
    (可选)
    DOMElement

    If provided then the element will be used to represent the enable/disable operation

    返回值

    boolean

    Current animation state.


上一篇:下一篇: