javascript - Scroll to bottom of page, only if the user already was at the bottom before DOM manipulation -
i'd learn how use window.scrollto
.
here's desired behavior:
- determine if user scrolled bottom of page, or no scroll bar visible
- then want grow div, working
- if #1 true, use
window.scrollto
scroll bottom of page after div has grown changed window height.
ideas?
working han's idea, can detect whether window scrolled bottom this:
$('button').click(function(){ var shouldscroll = $(document).scrolltop() + $(window).height() === $(document).height(); $('<div>added content</div>').appendto('body'); if(shouldscroll) { $(window).scrolltop(document.body.scrollheight); } });
updated jsfiddle here: http://jsfiddle.net/jameskovacs/nqntc/1/
Comments
Post a Comment