Pārlūkot izejas kodu

use css transition for revert. strip jq

Adam Shaw 7 gadi atpakaļ
vecāks
revīzija
70e76e98c6
1 mainītis faili ar 13 papildinājumiem un 6 dzēšanām
  1. 13 6
      src/common/MouseFollower.ts

+ 13 - 6
src/common/MouseFollower.ts

@@ -1,8 +1,8 @@
-import * as $ from 'jquery'
 import {
   getEvY,
   getEvX,
-  getEvIsTouch
+  getEvIsTouch,
+  whenTransitionDone
 } from '../util/dom-event'
 import { removeElement, applyStyle } from '../util/dom-manip'
 import { default as ListenerMixin, ListenerInterface } from './ListenerMixin'
@@ -79,6 +79,7 @@ export default class MouseFollower {
   // Causes the element to stop following the mouse. If shouldRevert is true, will animate back to original position.
   // `callback` gets invoked when the animation is complete. If no animation, it is invoked immediately.
   stop(shouldRevert, callback) {
+    let { el } = this
     let revertDuration = this.options.revertDuration
 
     const complete = () => { // might be called by .animate(), which might change `this` context
@@ -99,12 +100,18 @@ export default class MouseFollower {
 
       if (shouldRevert && revertDuration && !this.isHidden) { // do a revert animation?
         this.isAnimating = true
-        $(this.el).animate({
+
+        // do before position change
+        el.style.transition = 'top ' + revertDuration + 'ms, left ' + revertDuration + 'ms'
+
+        applyStyle(el, {
           top: this.top0,
           left: this.left0
-        }, {
-          duration: revertDuration,
-          complete: complete
+        })
+
+        whenTransitionDone(el, function() {
+          el.style.transition = ''
+          complete()
         })
       } else {
         complete()