javascript - Keep overflow div scrolled to bottom unless user scrolls up -


i have div 300 pixels big , want when page loads scroll bottom of content. div has content dynamically added , needs stay scrolled way down. if user decides scroll don't want jump bottom until user scrolls way down again

is possible have div stay scrolled bottom unless user scrolls , when user scrolls bottom needs keep @ bottom when new dynamic content added. how go bout creating this.

well while might you:

var element = document.getelementbyid("yourdivid"); element.scrolltop = element.scrollheight; 

[edit], match comment...

function updatescroll(){     var element = document.getelementbyid("yourdivid");     element.scrolltop = element.scrollheight; } 

whenever content added, call updatescroll(), or set timer:

//once second setinterval("updatescroll",1000); 

if want update if user didn't move:

var scrolled = false; function updatescroll(){     if(!scrolled){         var element = document.getelementbyid("yourdivid");         element.scrolltop = element.scrollheight;     } }  $("#yourdivid").on('scroll', function(){     scrolled=true; }); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -