Skip to content

Instantly share code, notes, and snippets.

@stefanjudis
Last active May 3, 2023 18:33
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanjudis/bac4b53b481df2b4ed7e90967aa54561 to your computer and use it in GitHub Desktop.
Save stefanjudis/bac4b53b481df2b4ed7e90967aa54561 to your computer and use it in GitHub Desktop.
ScrollContainer always on bottom using MutationObserver using a vue.js directive
export default {
bind() {
let element = this.el;
this.observer = new MutationObserver( ( mutations ) => {
for ( var i = 0; i < mutations.length; i++ ) {
// adjust element scrollTop depending on it's changed height
element.scrollTop = element.scrollHeight;
}
} ) ;
this.observer.observe( this.el, {
childList : true,
subtree : true,
characterData : true
} );
},
unbind() {
this.observer.disconnect();
}
};
@stryju
Copy link

stryju commented Jul 4, 2016

what do you create theelement reference for?

@stefanjudis
Copy link
Author

stefanjudis commented Jul 4, 2016

@stryju When I tested the this context switched ( ignoring the arrow function )... not sure what the issues was. :)

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