read image style.top

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • joerg pfeffer

    read image style.top

    hello,

    I want to read the style.top of an image when I open the page with:
    document.getEle mentById("myima ge").style.to p

    But unfortunately the value has no properties....

    Does this happen, since the image isn't loaded already?

    thanks
    Joerg
  • ASM

    #2
    Re: read image style.top

    joerg pfeffer wrote:[color=blue]
    > hello,
    >
    > I want to read the style.top of an image when I open the page with:
    > document.getEle mentById("myima ge").style.to p
    >
    > But unfortunately the value has no properties....[/color]

    objcts (div, img, etc) have only placement properties
    if they are set in absolute position ...
    or if they have been moved (re-stylled) by JS

    and, on my idea, the right call would be :
    myTop = document.getEle mentById("myima ge").top
    (to verify !)
    [color=blue]
    > Does this happen, since the image isn't loaded already?[/color]

    and, of course, the call to myTop
    must wait the page is loaded
    (image loading itself is of no importance)


    --
    Stephane Moriaux et son [moins] vieux Mac

    Comment

    • RobG

      #3
      Re: read image style.top

      joerg pfeffer wrote:[color=blue]
      > hello,
      >
      > I want to read the style.top of an image when I open the page with:
      > document.getEle mentById("myima ge").style.to p
      >
      > But unfortunately the value has no properties....
      >
      > Does this happen, since the image isn't loaded already?
      >[/color]

      As Stephanie pointed out, an element's style object will not have values
      for properties inherited from CSS rules or general layout.

      You need to investigate getComputedStyl e and getCurrentStyle , try the
      following function but beware that Mozilla et al want standard
      hyphenated style names and IE wants them camelCase. In if you only want
      'top', then it won't be a problem:

      function GetCurrentStyle ( el, prop ) {
      if ( window.getCompu tedStyle ) {
      // Mozilla et al
      return window.getCompu tedStyle(el, '').getProperty Value(prop) );
      } // IE5+
      else if ( el.currentStyle ) {
      return el.currentStyle[prop];
      } // IE4
      else if ( el.style ) {
      return el.style[prop];
      }
      }


      There is a thread "RegExp for hyphen to camelCase" that discusses
      solutions to the camelCase/hyphen issue:

      <URL:http://groups-beta.google.com/group/comp.lang.javas cript/browse_frm/thread/6c90313661245bb 5/72776c776ce21e4 8?q=camelcase&r num=1&hl=en#727 76c776ce21e48>


      --
      Rob

      Comment

      Working...