1. #1
    Sencha Premium Member
    Join Date
    Aug 2011
    Posts
    168
    Vote Rating
    2
    Answers
    1
    GertBoers is on a distinguished road

      0  

    Default Unanswered: changing margins depending on the device

    Unanswered: changing margins depending on the device


    Is something like this possible?

    I'd like the margin-top of an image be half the image height... The image height can change according to the device though...

    I'm not a programmer... so my code isn't working obviously. Anyone got a solution?

    Code:
    var imgImg=document.getElementById('i');
    var imgHeight=imgImg.style.height;
    var halfHeight=imgHeight/2;
    
    
    templateTeam = new Ext.XTemplate(
      '<div class="storeDetailView"><img id="i" src="{img}" alt="" class="largepic" style="margin-top:-'+halfHeight+'px" />',
      '</div>'
    );
    Thanks

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,647
    Vote Rating
    899
    Answers
    3575
    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


    So you have to wait for the image to be rendered. Then you need to get the height of the image and then set the margin to what you need...

    Code:
    var el = Ext.get('imgId'),
        height = el.getHeight(),
        topMargin = height / 2;
    
    el.setStyle('margin-top', topMargin);
    Something like that may work.
    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 Premium Member
    Join Date
    Aug 2011
    Posts
    168
    Vote Rating
    2
    Answers
    1
    GertBoers is on a distinguished road

      0  

    Default


    Thx but i'm missing something:

    Cannot call method 'getHeight' of null...
    So it's not finding my elements with id="i".

    I'm a bit confused, where exactly should i put this code?

    Code:
    var el = Ext.get('i');
        height = el.getHeight();
        topMargin = height / 2;
    el.setStyle('margin-top', topMargin);

Thread Participants: 1