Last active
May 3, 2023 18:33
-
-
Save stefanjudis/bac4b53b481df2b4ed7e90967aa54561 to your computer and use it in GitHub Desktop.
ScrollContainer always on bottom using MutationObserver using a vue.js directive
This file contains hidden or 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 { | |
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 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
what do you create the
element
reference for?