Hybrid View

  1. #1
    Sencha User
    Join Date
    Oct 2011
    Posts
    14
    Vote Rating
    1
    javaBear is on a distinguished road

      0  

    Default How to get the x and y position inside an image

    How to get the x and y position inside an image


    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)?

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,548
    Vote Rating
    872
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    You could get the scroll offset from the Scroller and do some math.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Oct 2011
    Posts
    14
    Vote Rating
    1
    javaBear is on a distinguished road

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    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?

  4. #4
    Sencha User
    Join Date
    Oct 2011
    Posts
    14
    Vote Rating
    1
    javaBear is on a distinguished road

      0  

    Default


    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())?

  5. #5
    Sencha User
    Join Date
    Oct 2011
    Posts
    14
    Vote Rating
    1
    javaBear is on a distinguished road

      0  

    Default


    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?

  6. #6
    Sencha User
    Join Date
    Oct 2011
    Posts
    14
    Vote Rating
    1
    javaBear is on a distinguished road

      0  

    Default


    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?

Thread Participants: 1

Tags for this Thread