Change page margins

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jourik Feenstra

    Change page margins

    I'm trying to write a javascript function that 'slides' a page a bit down by
    retreiving the current top-margin of the body, and then setting it to the
    old margin + 50px extra..
    The problem here is, I can't seem to retreive the current margin.
    Here's what I use now (which returns an empty value):

    <html>
    <style> body { background-color: yellow; margin-top: 100px; }</style>
    <body>
    <script language='javas cript'>
    document.write( 'current margin: ' + document.body.s tyle.marginTop) ;
    </script>
    </body>
    </html>

    Any ideas?


  • Michael Scovetta

    #2
    Re: Change page margins

    Try using document.body.c urrentStyle.mar ginTop:


    <html>
    <style> body { background-color: yellow; margin-top: 100px; }</style>
    <body topmargin="3">
    <script language='javas cript'>
    alert('current margin: ' + document.body.c urrentStyle.mar ginTop);
    </script>
    </body>
    </html>

    --output: current margin: 100px


    Mike


    "Jourik Feenstra" <jourik@selwerd .nl> wrote in message news:<bue96n$jl p$1@info.servic e.rug.nl>...[color=blue]
    > I'm trying to write a javascript function that 'slides' a page a bit down by
    > retreiving the current top-margin of the body, and then setting it to the
    > old margin + 50px extra..
    > The problem here is, I can't seem to retreive the current margin.
    > Here's what I use now (which returns an empty value):
    >
    > <html>
    > <style> body { background-color: yellow; margin-top: 100px; }</style>
    > <body>
    > <script language='javas cript'>
    > document.write( 'current margin: ' + document.body.s tyle.marginTop) ;
    > </script>
    > </body>
    > </html>
    >
    > Any ideas?[/color]

    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: Change page margins

      nospam_googlegr oups@scovetta.c om (Michael Scovetta) writes:
      [color=blue]
      > Try using document.body.c urrentStyle.mar ginTop:[/color]

      That works in IE only.
      The W3C DOM method is
      document.defaul tView.getComput edStyle(documen t.body,"").marg inTop
      It works in Mozilla and (IIRC) Opera 7.20+.
      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      Working...