PDA

View Full Version : How to reset scrolling panel position to top



dankhan
11 Oct 2010, 1:06 AM
Hi,

Looked at a few examples but can't figure this one out.

I've got a button on each page of my carousel that shows an overlay with a scroller - I'm reusing the same overlay on cards. Upon loading the overlay I want to reset the position of the scrolled content back to the top since if i scrolled down a long page of content on a previous card, the next time I load the overlay with new content the position stays at the bottom.

The examples (e.g. twitter) imply I can use the [Panel].scroller.scrollTo({x: 0, y:0}) function, but when I call this on a global object, it says that [Panel].scroller is undefined. I've tried a few different routes around this including creating an Ext.util.Scroller object and referencing this, but still no good?

Here's my snippet




// Global
var overlay

// The overlay window
overlay = new Ext.Panel({
floating: true,
modal: true,
centered: true,
styleHtmlContent: true,
dockedItems: overlayTb,
scroll: 'vertical',
cls: 'overlaycontent'
});

...

// Callback to show the overlay on button click
var showOverlay = function(btn, event) {
overlay.update('content');
overlay.scroller.scrollTo({x:0,y:0}, false);
overlay.show();
};



Here's my safari error:


TypeError: Result of expression 'overlay.scroller' [undefined] is not an object.

evant
11 Oct 2010, 1:08 AM
Well, I would guess it fails the first time, because the scroller doesn't exist yet because the panel hasn't been rendered, so just use a condition to check whether it exists or not.

gabrielstuff
11 Oct 2010, 2:13 AM
Yes, evant is actually right. I made the same mistake. Always check if something exist before asking for a function. Actually, we were wondering why some elements are only available after rendering state ?
Also, why did you choose not to automatically once a card has lost focus to scroll back at the top ?? I can get it why in the list, but that is all...

dankhan
11 Oct 2010, 10:37 PM
Yes, evant is actually right. I made the same mistake. Always check if something exist before asking for a function. Actually, we were wondering why some elements are only available after rendering state ?
Also, why did you choose not to automatically once a card has lost focus to scroll back at the top ?? I can get it why in the list, but that is all...

Duh! Yeh, thanks for this one. Sometimes that second pair of eyes helps. I think I'm so new learning this stuff that often the most obvious things go overlooked expecting it to be a much deeper problem! And yeh, oblur is much better, didn't think past this first limiting problem.

Cheers,
-Dan