PDA

View Full Version : How to get the x and y position inside an image



javaBear
10 Sep 2012, 10:16 AM
I have an image that I would like to be able to tap on and get the x and y position of the "tap" event.
In the tap event, e.pageX and e.pageY give me the absolute position on the screen. If the page has been scrolled, then the value is still relative to the viewport and not to the page.
How can I get the position of the tap event?
Also, how can I get the position of the image (or its container)?

mitchellsimoens
12 Sep 2012, 10:19 AM
You could get the scroll offset from the Scroller and do some math.

javaBear
12 Sep 2012, 12:02 PM
You could get the scroll offset from the Scroller and do some math.

Yes, I've seen that being suggested. However, I cannot find any container that has a valid scroller... :((
How do I get to the object with the scroller?

javaBear
14 Sep 2012, 1:08 PM
I've now check every parent (container, panel and view) of the image but none them has a valid scroller...
Two of them returns an object from getScrollable(), they are both of type Ext.scroll.View.
However, they fail with this error: Uncaught TypeError: Object [object Object] has no method 'getScroller'

How do I get the scroller (using getScroller())?

javaBear
14 Sep 2012, 1:24 PM
Checked the source, src/scroll/View.js and found something strange (I think). The getScroller() method does not seem to be implemented, there is only a comment in the file:
...
/**
* @method getScroller
* Returns the scroller instance in this view. Checkout the documentation of {@link Ext.scroll.Scroller} and
* {@link Ext.Container#getScrollable} for more information.
* @return {Ext.scroll.View} The scroller
*/


/**
* @private
*/
processConfig: function(config) {
...

Is this an error or am I looking in the wrong file?
:-/

javaBear
17 Sep 2012, 12:05 AM
I think I found the solution: I just added the getScroller() method:

getScroller: function() {
return this.scroller;
}


Now I get the current scrolling position by using: getScroller().postition.y

Still the question remains: Why is getScroller() not implemented in scroll/View.js?