Results 1 to 4 of 4

Thread: Image tap event get relative coordinates?

  1. #1

    Default Image tap event get relative coordinates?

    So if I have image in my application created with
    Code:
    Ext.create('Ext.Img');
    and I have a tap event listener attached to it in my controller then how can I get the coordinates of tap within the picture it self?

  2. #2
    Sencha Premium User
    Join Date
    Feb 2010
    Location
    Chicago
    Posts
    71
    Answers
    17

    Default

    Grab it off the event object.

    Quick Example
    Code:
            var img = Ext.create('Ext.Img', {
                src: 'http://www.sencha.com/assets/images/sencha-avatar-64x64.png',
                height: 64,
                width: 64,
                listeners : {
                    scope : this,
                    tap   : function(cmp, e){
                        console.log(e.getXY());
                    }
                }
            });
            Ext.Viewport.add(img);

  3. #3

    Default Are those coordinates relative?

    Aren't those coordinates the window ones that you can get from tap event?

  4. #4
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,388
    Answers
    3997

    Default

    Like @Johnny Major said to do only you need to subtract e.getXY() coords from the image's coords:



    The fiddle you can drag around the image but the coords it logs out will be what they are within the image.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

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
  •