Dynamically Change CSS layer dimensions?

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

    #1

    Dynamically Change CSS layer dimensions?

    I don't know much about javascript, so take it easy on me. Is there a way to
    dynamically change a CSS layers dimensions on the fly. Here is what I'm
    doing. I have a bunch of thumbnails that when clicked on, will open up the
    full view in a CSS layer, as opposed to a pop-up window let's say. I had
    this before, but with one layer for each image, and as you might imagine,
    the markup was way too bloated. So can I just change the css layers
    dimensions on the fly. It is important that the layer be sized precisely
    because, there is content surrounding the image, like a close button that
    hides the layer.


  • Lasse Reichstein Nielsen

    #2
    Re: Dynamically Change CSS layer dimensions?

    "TheKeith" <no@spam.com> writes:
    [color=blue]
    > I don't know much about javascript, so take it easy on me. Is there a way to
    > dynamically change a CSS layers dimensions on the fly.[/color]

    I *think* I know what you are talking about. However, the word "layer" is
    being used with several different meanings, so it should be avoided when
    you want to be precise.

    What you have is probably an absolutely positioned block element.

    You can change its dimensions by setting the CSS properties "width"
    and "height".

    var elem = document.getEle mentById("divId ");
    elem.style.widt h = "200px";
    elem.style.heig ht = "300px"
    [color=blue]
    > It is important that the layer be sized precisely because, there is
    > content surrounding the image, like a close button that hides the
    > layer.[/color]

    You'll have to find the size you need then.

    /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

    • TheKeith

      #3
      Re: Dynamically Change CSS layer dimensions?


      "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
      news:oew9ylzp.f sf@hotpop.com.. .[color=blue]
      > "TheKeith" <no@spam.com> writes:
      >[color=green]
      > > I don't know much about javascript, so take it easy on me. Is there a[/color][/color]
      way to[color=blue][color=green]
      > > dynamically change a CSS layers dimensions on the fly.[/color]
      >
      > I *think* I know what you are talking about. However, the word "layer" is
      > being used with several different meanings, so it should be avoided when
      > you want to be precise.
      >
      > What you have is probably an absolutely positioned block element.
      >
      > You can change its dimensions by setting the CSS properties "width"
      > and "height".
      >
      > var elem = document.getEle mentById("divId ");
      > elem.style.widt h = "200px";
      > elem.style.heig ht = "300px"
      >[color=green]
      > > It is important that the layer be sized precisely because, there is
      > > content surrounding the image, like a close button that hides the
      > > layer.[/color]
      >
      > You'll have to find the size you need then.[/color]

      Thanks a lot I really appreciate it. I'm trying to modify your code a little
      so that it works as a function. My javascript isn't very good--can you take
      a look at what I got and tell me what's wrong?


      <html>
      <head>
      <script type="text/JavaScript">
      <!--
      function twohundredsquar e(divid,divwidt h,divheight) {
      boxdimensions = getElementById (divid);
      boxdimensions.s tyle.width = divwidth;
      boxdimensions.s tyle.height = divheight;
      }
      //-->
      </script>
      </head>
      <body>
      <a href="javascrip t:twohundredsqu are("blue","200 px","200px");"> change to 200
      x 200</a><br>
      <div id="blue" style="position :absolute; left:209px; top:89px; width:115px;
      height:95px; z-index:1; background-color: #0000FF; layer-background-color:
      #0000FF; border: 1px none #000000;"></div>
      </body>
      </html>


      Basically the link is supposed to change the dimensions of the div element
      by calling on that function. Any help would be great--thanks.


      Comment

      • TheKeith

        #4
        Re: Dynamically Change CSS layer dimensions?

        "TheKeith" <no@spam.com> wrote in message
        news:9pidnTOSYd FizwqiU-KYvg@giganews.c om...[color=blue]
        >
        > "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
        > news:oew9ylzp.f sf@hotpop.com.. .[color=green]
        > > "TheKeith" <no@spam.com> writes:
        > >[color=darkred]
        > > > I don't know much about javascript, so take it easy on me. Is there a[/color][/color]
        > way to[color=green][color=darkred]
        > > > dynamically change a CSS layers dimensions on the fly.[/color]
        > >
        > > I *think* I know what you are talking about. However, the word "layer"[/color][/color]
        is[color=blue][color=green]
        > > being used with several different meanings, so it should be avoided when
        > > you want to be precise.
        > >
        > > What you have is probably an absolutely positioned block element.
        > >
        > > You can change its dimensions by setting the CSS properties "width"
        > > and "height".
        > >
        > > var elem = document.getEle mentById("divId ");
        > > elem.style.widt h = "200px";
        > > elem.style.heig ht = "300px"
        > >[color=darkred]
        > > > It is important that the layer be sized precisely because, there is
        > > > content surrounding the image, like a close button that hides the
        > > > layer.[/color]
        > >
        > > You'll have to find the size you need then.[/color]
        >
        > Thanks a lot I really appreciate it. I'm trying to modify your code a[/color]
        little[color=blue]
        > so that it works as a function. My javascript isn't very good--can you[/color]
        take[color=blue]
        > a look at what I got and tell me what's wrong?
        >
        >
        > <html>
        > <head>
        > <script type="text/JavaScript">
        > <!--
        > function twohundredsquar e(divid,divwidt h,divheight) {
        > boxdimensions = getElementById (divid);
        > boxdimensions.s tyle.width = divwidth;
        > boxdimensions.s tyle.height = divheight;
        > }
        > //-->
        > </script>
        > </head>
        > <body>
        > <a href="javascrip t:twohundredsqu are("blue","200 px","200px");"> change to[/color]
        200[color=blue]
        > x 200</a><br>
        > <div id="blue" style="position :absolute; left:209px; top:89px;[/color]
        width:115px;[color=blue]
        > height:95px; z-index:1; background-color: #0000FF; layer-background-color:
        > #0000FF; border: 1px none #000000;"></div>
        > </body>
        > </html>
        >
        >
        > Basically the link is supposed to change the dimensions of the div element
        > by calling on that function. Any help would be great--thanks.[/color]


        nevermind, I got it working. Here is what I did:

        <html>
        <head>
        <title>Untitl ed Document</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <script type="text/JavaScript">
        <!--
        function viewer_dimensio ns(divid,divwid th,divheight) {
        specs = document.getEle mentById(divid) ;
        specs.style.wid th = divwidth;
        specs.style.hei ght = divheight;
        }
        //-->
        </script>
        </head>
        <body>
        <a href="javascrip t:viewer_dimens ions('blue','20 0px','200px')"> change to 200
        x 200</a>
        <div id="blue" style="position :absolute; left:209px; top:89px; width:115px;
        height:95px; z-index:1; background-color: #0000FF"></div>
        </body>
        </html>


        Comment

        • Lasse Reichstein Nielsen

          #5
          Re: Dynamically Change CSS layer dimensions?

          "TheKeith" <no@spam.com> writes:
          [color=blue]
          > nevermind, I got it working. Here is what I did:[/color]

          Remember to add a !DOCTYPE declaration for the version of HTML that you use.
          It can also put modern browsers in standards mode.
          [color=blue]
          > <script type="text/JavaScript">
          > <!--[/color]

          You don't need HTML comments in your Javascript code.
          [color=blue]
          > function viewer_dimensio ns(divid,divwid th,divheight) {
          > specs = document.getEle mentById(divid) ;[/color]

          I would make "specs" a local variable instead of a global one. I.e.,
          var specs = document.getEle mentById(divid) :
          [color=blue]
          > <a href="javascrip t:viewer_dimens ions('blue','20 0px','200px')"> change to 200
          > x 200</a>[/color]

          It is not recommended to use javascript:-URI's.
          <URL:http://jibbering.com/faq/#FAQ4_24>
          The intended usage of these is to return the new content of the page,
          so using them can cause the current page to disappear, if one is not
          careful. If you just want to run some code, use the onclick attribute:
          <a href="WhyYouNee dJS.html"
          onclick="viewer _dimensions('bl ue','200px','20 0px');return false;">

          Otherwise, good luck :)
          /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

          • TheKeith

            #6
            Re: Dynamically Change CSS layer dimensions?


            "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
            news:7k2w49e5.f sf@hotpop.com.. .[color=blue]
            > "TheKeith" <no@spam.com> writes:
            >[color=green]
            > > nevermind, I got it working. Here is what I did:[/color]
            >
            > Remember to add a !DOCTYPE declaration for the version of HTML that you[/color]
            use.[color=blue]
            > It can also put modern browsers in standards mode.[/color]

            I always do--I just left it out for clarification's sake.
            [color=blue]
            >[color=green]
            > > <script type="text/JavaScript">
            > > <!--[/color]
            >
            > You don't need HTML comments in your Javascript code.[/color]

            Really! I thought you were supposed to use it to hide the script from
            browsers that can't read it? Is that just something that most programmers
            have abandoned since all newer browsers support js?

            [color=blue]
            >[color=green]
            > > function viewer_dimensio ns(divid,divwid th,divheight) {
            > > specs = document.getEle mentById(divid) ;[/color]
            >
            > I would make "specs" a local variable instead of a global one. I.e.,
            > var specs = document.getEle mentById(divid) :[/color]

            I didn't know there was a difference between declaring your variables with
            the var in front and without. Could you explain the difference? Thanks.


            [color=blue][color=green]
            > > <a href="javascrip t:viewer_dimens ions('blue','20 0px','200px')"> change to[/color][/color]
            200[color=blue][color=green]
            > > x 200</a>[/color]
            >
            > It is not recommended to use javascript:-URI's.
            > <URL:http://jibbering.com/faq/#FAQ4_24>
            > The intended usage of these is to return the new content of the page,
            > so using them can cause the current page to disappear, if one is not
            > careful. If you just want to run some code, use the onclick attribute:
            > <a href="WhyYouNee dJS.html"
            > onclick="viewer _dimensions('bl ue','200px','20 0px');return false;">[/color]

            Got it--much appreciated. What should I put in the href section?

            [color=blue]
            > Otherwise, good luck :)[/color]

            I really appreciate all your help. Thanks a lot.


            Comment

            • Lasse Reichstein Nielsen

              #7
              Re: Dynamically Change CSS layer dimensions?

              "TheKeith" <no@spam.com> writes:
              [color=blue]
              > "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
              > news:7k2w49e5.f sf@hotpop.com.. .[color=green]
              > > Remember to add a !DOCTYPE[/color][/color]
              ....[color=blue]
              > I always do--I just left it out for clarification's sake.[/color]

              Good :)
              [color=blue][color=green]
              > > You don't need HTML comments in your Javascript code.[/color]
              >
              > Really! I thought you were supposed to use it to hide the script from
              > browsers that can't read it?[/color]

              Correct.

              Those browsers are not the ones that just don't support Javascript. It
              is the ones that don't even understand the script *tag*. The latest
              such Netscape was version 1, the latest IE was version 2. I haven't
              seen any browser made after 1997 that didn't understand the script tag
              well enough to not render the content.

              There are some, dated, utilities that gets confuzed. I wouldn't worry
              about that unless I use them myself, as the author of the page.
              [color=blue]
              > Is that just something that most programmers have abandoned since
              > all newer browsers support js?[/color]

              Too few programmers have abandoned it. The Crusade Against HTML
              Comments in Javscript(TM) will fight this bad habit to the end! :)
              It is time to move on.

              It is also a bad idea in XHTML, since a conformant XML parser must
              ignore everything inside comments *before* starting to interpret it
              (IIRC).
              [color=blue]
              > I didn't know there was a difference between declaring your variables with
              > the var in front and without. Could you explain the difference? Thanks.[/color]

              Without the var in front, you don't *declare* the variable. Assigning
              to an undeclared variable name will create a new global variable of
              that name.

              Inside a function, the "var" keyword is used to declare local variables.
              If you have a global variable called "foo" and a function declares a local
              variable of the same name, then inside the function body, only the local
              variable is visible. Changes to it doesn't affect the global variable.

              Example:
              ---
              <script type="text/javascript">
              var foo = 42; // *declares* variable in global scope
              function bar() {
              var foo = "arglebargl e"; // declares variable as local in function's scope
              foo += foo;
              return foo;
              }
              alert(bar());
              alert(foo);
              </script>
              ---
              This alerts first "arglebarglearg lebargle" and then "42".

              You can assign to global variables without declaring them first.
              ---
              <script type="text/javascript">
              var foo = 42;
              bar = 37;
              alert(foo + bar);
              </script>
              ---
              This alerts "79". Afterwards, both "foo" and "bar" are global variables
              (i.e., properties of the global object).

              You cannot *read* from undeclared global variables
              ---
              <script type="text/javascript">
              var foo;
              alert(foo);
              alert(bar);
              </script>
              ---
              This alerts "undefined" (the value given to a declared but
              uninitialized variable), and then it gives an error because
              "bar" is an undeclared variable.

              There is no reason not to declare your global variables. In fact,
              recently, someone had troubles because he was using undeclared global
              variables with the same name as an element's id. I believe declaring
              the variables solved the problem.

              There is absolutely no reason not to declare your local variables.
              Programming is much easier when you have local scopes. You don't have
              to worry that your variable is named the same as some other function's
              variable.
              [color=blue]
              > Got it--much appreciated. What should I put in the href section?[/color]

              A link to a page that either:

              1) substitutes for what you try to do, just without the javascript.
              E.g., if you want to open a fancy window to show an image, then put
              plain link to the image, so people without Javascript can still see
              it. They just miss the extra bells and whistles.
              or,
              2) if that is not possible, put a link to a page that explains why
              your page requires Javascript in order to function.

              /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

              • TheKeith

                #8
                Re: Dynamically Change CSS layer dimensions?


                "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
                news:1xt33l66.f sf@hotpop.com.. .[color=blue]
                > "TheKeith" <no@spam.com> writes:
                >[color=green]
                > > "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
                > > news:7k2w49e5.f sf@hotpop.com.. .[color=darkred]
                > > > Remember to add a !DOCTYPE[/color][/color]
                > ...[color=green]
                > > I always do--I just left it out for clarification's sake.[/color]
                >
                > Good :)
                >[color=green][color=darkred]
                > > > You don't need HTML comments in your Javascript code.[/color]
                > >
                > > Really! I thought you were supposed to use it to hide the script from
                > > browsers that can't read it?[/color]
                >
                > Correct.
                >
                > Those browsers are not the ones that just don't support Javascript. It
                > is the ones that don't even understand the script *tag*. The latest
                > such Netscape was version 1, the latest IE was version 2. I haven't
                > seen any browser made after 1997 that didn't understand the script tag
                > well enough to not render the content.
                >
                > There are some, dated, utilities that gets confuzed. I wouldn't worry
                > about that unless I use them myself, as the author of the page.
                >[color=green]
                > > Is that just something that most programmers have abandoned since
                > > all newer browsers support js?[/color]
                >
                > Too few programmers have abandoned it. The Crusade Against HTML
                > Comments in Javscript(TM) will fight this bad habit to the end! :)
                > It is time to move on.
                >
                > It is also a bad idea in XHTML, since a conformant XML parser must
                > ignore everything inside comments *before* starting to interpret it
                > (IIRC).
                >[color=green]
                > > I didn't know there was a difference between declaring your variables[/color][/color]
                with[color=blue][color=green]
                > > the var in front and without. Could you explain the difference? Thanks.[/color]
                >
                > Without the var in front, you don't *declare* the variable. Assigning
                > to an undeclared variable name will create a new global variable of
                > that name.
                >
                > Inside a function, the "var" keyword is used to declare local variables.
                > If you have a global variable called "foo" and a function declares a local
                > variable of the same name, then inside the function body, only the local
                > variable is visible. Changes to it doesn't affect the global variable.
                >
                > Example:
                > ---
                > <script type="text/javascript">
                > var foo = 42; // *declares* variable in global scope
                > function bar() {
                > var foo = "arglebargl e"; // declares variable as local in function's[/color]
                scope[color=blue]
                > foo += foo;
                > return foo;
                > }
                > alert(bar());
                > alert(foo);
                > </script>
                > ---
                > This alerts first "arglebarglearg lebargle" and then "42".
                >
                > You can assign to global variables without declaring them first.
                > ---
                > <script type="text/javascript">
                > var foo = 42;
                > bar = 37;
                > alert(foo + bar);
                > </script>
                > ---
                > This alerts "79". Afterwards, both "foo" and "bar" are global variables
                > (i.e., properties of the global object).
                >
                > You cannot *read* from undeclared global variables
                > ---
                > <script type="text/javascript">
                > var foo;
                > alert(foo);
                > alert(bar);
                > </script>
                > ---
                > This alerts "undefined" (the value given to a declared but
                > uninitialized variable), and then it gives an error because
                > "bar" is an undeclared variable.
                >
                > There is no reason not to declare your global variables. In fact,
                > recently, someone had troubles because he was using undeclared global
                > variables with the same name as an element's id. I believe declaring
                > the variables solved the problem.
                >
                > There is absolutely no reason not to declare your local variables.
                > Programming is much easier when you have local scopes. You don't have
                > to worry that your variable is named the same as some other function's
                > variable.
                >[color=green]
                > > Got it--much appreciated. What should I put in the href section?[/color]
                >
                > A link to a page that either:
                >
                > 1) substitutes for what you try to do, just without the javascript.
                > E.g., if you want to open a fancy window to show an image, then put
                > plain link to the image, so people without Javascript can still see
                > it. They just miss the extra bells and whistles.
                > or,
                > 2) if that is not possible, put a link to a page that explains why
                > your page requires Javascript in order to function.
                >[/color]

                Hey thanks again for the great info.


                Comment

                • Jim Ley

                  #9
                  Re: Dynamically Change CSS layer dimensions?

                  On 23 Oct 2003 19:42:41 +0200, Lasse Reichstein Nielsen
                  <lrn@hotpop.com > wrote:
                  [color=blue]
                  >It is also a bad idea in XHTML, since a conformant XML parser must
                  >ignore everything inside comments *before* starting to interpret it
                  >(IIRC).[/color]

                  AIUI it's may not must, but it's an optimisation I'd expect.

                  Jim.
                  --
                  comp.lang.javas cript FAQ - http://jibbering.com/faq/

                  Comment

                  • Lasse Reichstein Nielsen

                    #10
                    Re: Dynamically Change CSS layer dimensions?

                    jim@jibbering.c om (Jim Ley) writes:
                    [color=blue]
                    > AIUI it's may not must, but it's an optimisation I'd expect.[/color]

                    You are correct.
                    ---[about comments]---
                    They are not part of the document's character data; an XML processor
                    may, but need not, make it possible for an application to retrieve
                    the text of comments.
                    --- XML 1.0, 2nd edition - W3C recommendation ---

                    /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

                    • Jim Ley

                      #11
                      Re: Dynamically Change CSS layer dimensions?

                      On 24 Oct 2003 22:37:43 +0200, Lasse Reichstein Nielsen
                      <lrn@hotpop.com > wrote:
                      [color=blue]
                      >jim@jibbering. com (Jim Ley) writes:
                      >[color=green]
                      >> AIUI it's may not must, but it's an optimisation I'd expect.[/color]
                      >
                      >You are correct.
                      >---[about comments]---
                      > They are not part of the document's character data; an XML processor
                      > may, but need not, make it possible for an application to retrieve
                      > the text of comments.
                      >--- XML 1.0, 2nd edition - W3C recommendation ---[/color]

                      After a brief discussion today with Hixie, I actually think I was
                      wrong and you were right in the first place - the point being that a
                      comment inside an XHTML is exactly that - a comment, so none of the
                      data should be passed to the script engine irrelevant to whether the
                      UA actually keeps the comment in the DOM.

                      Sorry for misleading.

                      Jim.
                      --
                      comp.lang.javas cript FAQ - http://jibbering.com/faq/

                      Comment

                      Working...