PDA

View Full Version : scroll to bottom unless scrolled



ara.t.howard
17 Sep 2010, 2:32 PM
i have an app with a chat component - new messages appear at the bottom of the Ext.List. obviously i sometimes (if the user is *at* the bottom) want to append a message and scroll to ensure it's in view but, other times, such as when the user has scrolled up the list, do not want this behavior. essentially i want to code

unless(scrolled_away_from_bottom){
scroll_to_most_recent_message(message)
}

pointers?

evant
19 Sep 2010, 8:05 PM
Something like this:



Ext.setup({
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
icon: 'icon.png',
glossOnIcon: false,

onReady: function(){

var html = [],
i = 0,
scrolled = false;

setInterval(function(){
html.push('line ' + (++i));

var scroller = panel.scroller,
scrollY = scroller.getOffset().y,
maxY = Math.abs(scroller.bounds.y);

panel.update(html.join('<br />'));

if(!scrolled || scrollY == maxY){
scroller.scrollTo({
x: 0,
y: Math.abs(scroller.bounds.y)
}, false);
}




}, 500);

var panel = new Ext.Panel({
fullscreen: true,
scroll: 'vertical',
listeners: {
afterrender: function(c){
c.scroller.on('scroll', function(){
scrolled = true;
});
}
}
});
}
});

ara.t.howard
25 Sep 2010, 7:28 AM
that looks close - will try it!