Results 1 to 6 of 6

Thread: How to get the x and y position inside an image

  1. #1
    Sencha User
    Join Date
    Oct 2011
    Posts
    14
    Vote Rating
    1
      0  

    Default 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Vote Rating
    1272
      0  

    Default

    You could get the scroll offset from the Scroller and do some math.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  3. #3
    Sencha User
    Join Date
    Oct 2011
    Posts
    14
    Vote Rating
    1
      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
      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
      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
      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?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •