Created
April 13, 2013 18:15
Auto-scrolling extender for knockout.js observableArray objects
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
ko.extenders.scrollFollow = function (target, selector) { | |
target.subscribe(function (newval) { | |
var el = document.querySelector(selector); | |
// the scroll bar is all the way down, so we know they want to follow the text | |
if (el.scrollTop == el.scrollHeight - el.clientHeight) { | |
// have to push our code outside of this thread since the text hasn't updated yet | |
setTimeout(function () { el.scrollTop = el.scrollHeight - el.clientHeight; }, 0); | |
} | |
}); | |
return target; | |
}; |
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
var viewModel = { | |
someArray: ko.observableArray().extend({ scrollFollow: '#some_element' }) | |
}; | |
ko.applyBindings(viewModel); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment