PDA

View Full Version : Scrolling and getting element's position information



kevchuey
5 Aug 2010, 3:16 PM
Hi,

I have a vertical scrolling NestedList, and I am accessing each item's position information using the getPageBox method.


var pageBox = el.getPageBox();

When I first check the pageBox data prior to scrolling the NestedList, the data is correct. However, scrolling the NestedList doesn't alter the pageBox data (e.g., pageBox.top). I would have guessed that the pageBox data would change after you scroll.

Is this correct functionality? If so, what is the appropriate way to retrieve the data after an item has scrolled up/down?

If there is no way to get updated pageBox directly, is there an easy to way to find out how far the NestedList has scrolled? If I had that data, I could do some math and figure out the new position information.

Thanks!
Kevin

evant
5 Aug 2010, 6:50 PM
Ext.setup({
onReady: function(){
var html = [];
for(var i = 0; i < 100; ++i){
html.push(i);
}
var p = new Ext.Panel({
fullscreen: true,
scroll: 'vertical',
html: html.join('<br />')
});
p.scroller.on('scrollend', function(scroll, offset){
console.log(offset.y);
});
}
});


Also, to get the scroll at a particular point, use:



var offset = scroller.offset;


Might add in a method to do this, so it's documented.

evant
5 Aug 2010, 6:57 PM
Hey, what do you know, there's already a method there!



var offset = scroller.getOffset();

kevchuey
5 Aug 2010, 10:29 PM
Evan,

Thanks for the quick reply. I was able to find the scroller object off of a Component (in my case a NestedList), but only after I configured scroll: 'vertical'. I think I had originally left that configuration out, but still got the scrolling.

In any case, I still can't seem to get the right offset. In the below code, i have a scrolling NestedList, and the offset y-value (offset.y) always seems to be 0.

Also, the scroller.getOffset() method was undefined. I am also on an older version of Touch (I'm using 0.91), so perhaps this was all fixed in a later release?


var testObject;

var showOffset = function(item, event) {
alert("y offset: " + testObject.scroller.offset.vertical);
alert("y offset: " + testObject.scroller.getOffset().x);
};

Ext.setup({
onReady: function() {
testObject = new Ext.NestedList( {
fullscreen: true,
scroll: 'vertical',
items: [{
html: 'one',
height: 200,
handler: showOffset
},{
html: 'two',
height: 200,
handler: showOffset
},{
html: 'three',
height: 200,
handler: showOffset
},{
html: 'four',
height: 200,
handler: showOffset
}
]
});
}
});

kevchuey
5 Aug 2010, 10:34 PM
Yup,

That getOffset() method wasn't in 0.91 but is in the 0.93 release, but I am still getting 0 for the offset.y value regardless of how much I scroll.

Also, I think I had a typo in the code in a previous post that needs to be reviewed (I was outputting offset.x instead of offset.y in an alert statement), but even with the fix (looking for offset.y to be a non-zero #), it still doesn't work for me.

Thanks again,
Kevin

kevchuey
6 Aug 2010, 8:16 AM
Ok, nevermind. I went back and tried to access the pageBox position information again with 0.93 and it works after scrolling. So even though I can't get the scroll offset to work, I'm good to go!

Thanks Evan.