Skip to content

Instantly share code, notes, and snippets.

@lamchau
Created August 17, 2015 19:53
Show Gist options
  • Save lamchau/8798bf8dcf5bca75fb09 to your computer and use it in GitHub Desktop.
Save lamchau/8798bf8dcf5bca75fb09 to your computer and use it in GitHub Desktop.
`fadeIn` and `fadeOut` for Ember Component (ES6; ember-cli)
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());
}
});
@vinuel
Copy link

vinuel commented Jan 6, 2016

Hello!
This is pretty much what I'm looking for. I have got an ember component {{#header-note}}...{{/header-note}} a header-note.hbs and a header-note.js where I put your code in. But nothing happens ... Do I miss something? Using Ember 2.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment