Created
August 17, 2015 19:53
-
-
Save lamchau/8798bf8dcf5bca75fb09 to your computer and use it in GitHub Desktop.
`fadeIn` and `fadeOut` for Ember Component (ES6; ember-cli)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default Ember.Component.extend({ | |
fadeDurationInMilliseconds: 300, | |
didInsertElement() { | |
let duration = this.get("fadeDurationInMilliseconds"), | |
element = this.$(); | |
element.fadeIn(duration); | |
}, | |
willDestroyElement() { | |
let duration = this.get("fadeDurationInMilliseconds"), | |
current = this.$(), | |
clone = current.clone(), | |
previous = current.prev(), | |
next = current.next(); | |
// must clone the node and insert it accordingly for a smooth animation | |
if (previous.length) { | |
previous.after(clone); | |
} else if (next.length) { | |
next.before(clone); | |
} else { | |
let parent = current.parent(); | |
parent.append(clone); | |
} | |
clone.fadeOut(duration, () => clone.remove()); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello!
This is pretty much what I'm looking for. I have got an ember component
{{#header-note}}...{{/header-note}}
aheader-note.hbs
and aheader-note.js
where I put your code in. But nothing happens ... Do I miss something? Using Ember 2.2.