Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions src/components/transition.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export default function (Glide, Components, Events) {
* @type {Boolean}
*/
let disabled = false

let afterHandlers = []

const Transition = {
/**
Expand All @@ -23,7 +25,7 @@ export default function (Glide, Components, Events) {
return `${property} ${this.duration}ms ${settings.animationTimingFunc}`
}

return `${property} 0ms ${settings.animationTimingFunc}`
return 'none'
},

/**
Expand All @@ -46,15 +48,33 @@ export default function (Glide, Components, Events) {
},

/**
* Runs callback after animation.
* Runs handler after animation.
*
* @param {Function} callback
* @param {Function} handler
* @return {Void}
*/
after (callback) {
setTimeout(() => {
callback()
}, this.duration)
after (handler) {
let afterHandler = {
handler: () => {
clearTimeout(afterHandler.timerId)

handler()

afterHandlers.splice(afterHandlers.indexOf(afterHandler), 1)
},

timerId: setTimeout(() => {
afterHandler.handler()
}, this.duration)
}

afterHandlers.push(afterHandler)
},

callAfterHandlers () {
while (afterHandlers.length) {
afterHandlers[0].handler()
}
},

/**
Expand All @@ -77,6 +97,8 @@ export default function (Glide, Components, Events) {
disabled = true

this.set()

this.callAfterHandlers()
}
}

Expand Down