Results 1 to 4 of 4

Thread: Element.getLeft(true) broken - assumes CSS left property always set in px

    Wait! Looks like we don't have enough information to add this to bug database. Please follow this template bug format.
  1. #1
    Sencha Premium Member
    Join Date
    Sep 2011
    Posts
    51

    Default Element.getLeft(true) broken - assumes CSS left property always set in px

    By contrast, the setLeft method takes a string, so you could set CSS left to something like "10%". However, if you subsequently use getLeft to read the property, you'll get the number 10 (since getLeft uses parseInt on the CSS property value), which is very different from "10%"!

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,379

    Default

    Can I get a runnable test case?
    Mitchell Simoens @LikelyMitch

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

    Posts are my own, not any current, past or future employer's.

  3. #3
    Sencha Premium Member
    Join Date
    Sep 2011
    Posts
    51

    Default

    Mitchell,
    If you set an element's CSS left property to something like "50%", then use getLeft to read it, you'll get the number 50 (without the percent). Really, though, a test case seems somewhat superfluous; simple inspection of the getLeft routine...

    Code:
    getLeft : function(local){
            return !local ? this.getX() : parseInt(this.getStyle(LEFT), 10) || 0;
    }
    ...makes it pretty clear what's happening... Note the "parseInt" on a property value that could have a trailing '%'.

    Thanks,
    Brett S.

  4. #4
    Sencha Premium User mankz's Avatar
    Join Date
    Nov 2007
    Location
    Stockholm, Sweden
    Posts
    3,153

    Default

    Definitely a bit confusing. Case:

    Code:
    Ext.getBody().createChild({
       style:'position:absolute;left:50%'
    }).getLeft(true); // => 50

Posting Permissions

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