github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/public/libs/vue-1.0.24/src/transition/index.js (about)

     1  import {
     2    before,
     3    remove,
     4    transitionEndEvent
     5  } from '../util/index'
     6  
     7  /**
     8   * Append with transition.
     9   *
    10   * @param {Element} el
    11   * @param {Element} target
    12   * @param {Vue} vm
    13   * @param {Function} [cb]
    14   */
    15  
    16  export function appendWithTransition (el, target, vm, cb) {
    17    applyTransition(el, 1, function () {
    18      target.appendChild(el)
    19    }, vm, cb)
    20  }
    21  
    22  /**
    23   * InsertBefore with transition.
    24   *
    25   * @param {Element} el
    26   * @param {Element} target
    27   * @param {Vue} vm
    28   * @param {Function} [cb]
    29   */
    30  
    31  export function beforeWithTransition (el, target, vm, cb) {
    32    applyTransition(el, 1, function () {
    33      before(el, target)
    34    }, vm, cb)
    35  }
    36  
    37  /**
    38   * Remove with transition.
    39   *
    40   * @param {Element} el
    41   * @param {Vue} vm
    42   * @param {Function} [cb]
    43   */
    44  
    45  export function removeWithTransition (el, vm, cb) {
    46    applyTransition(el, -1, function () {
    47      remove(el)
    48    }, vm, cb)
    49  }
    50  
    51  /**
    52   * Apply transitions with an operation callback.
    53   *
    54   * @param {Element} el
    55   * @param {Number} direction
    56   *                  1: enter
    57   *                 -1: leave
    58   * @param {Function} op - the actual DOM operation
    59   * @param {Vue} vm
    60   * @param {Function} [cb]
    61   */
    62  
    63  export function applyTransition (el, direction, op, vm, cb) {
    64    var transition = el.__v_trans
    65    if (
    66      !transition ||
    67      // skip if there are no js hooks and CSS transition is
    68      // not supported
    69      (!transition.hooks && !transitionEndEvent) ||
    70      // skip transitions for initial compile
    71      !vm._isCompiled ||
    72      // if the vm is being manipulated by a parent directive
    73      // during the parent's compilation phase, skip the
    74      // animation.
    75      (vm.$parent && !vm.$parent._isCompiled)
    76    ) {
    77      op()
    78      if (cb) cb()
    79      return
    80    }
    81    var action = direction > 0 ? 'enter' : 'leave'
    82    transition[action](op, cb)
    83  }