Firefox2 problem with dynamic rendering (it's fine in IE, Safariand FF3)

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

    Firefox2 problem with dynamic rendering (it's fine in IE, Safariand FF3)

    I have a problem with Firefox 2 where if I resize the height of a DIV
    (using JavaScript), but the rest of the page below isn't being updated
    to reflect the new positions that affected items should be in. If I
    (using the mouse) resize the browser slightly, then somehow FF2 realizes
    things aren't in the right place and re-renders the page correctly. If I
    were to have a JS function ( document.body.r ender(); ) available to me
    for example, then I could manage this problem, but I don't. Or do I ?

    I'm assuming there's a CSS property that can influence this behavior
    somehow. Surely there must be, because *this simple test example below
    is working just perfectly*. On the complex page I'm trying to implement
    this on though, it doesn't work. The complex page has several CSS files
    in it and I can't get any information from anyone knowledgeable about it
    either. I've made this example below as minimalist as possible (removing
    title, doctype and anything else I think is irrelevant to the example).
    The only difference (in principle) between what I'm doing here (which
    works) and what I'm doing on the complex page (which doesn't work) is
    tons of CSS.

    On the complex page, when you click on "200", then "div1" overlaps
    "div2" until you resize the browser a little bit. And when you click on
    "50", you see "div2" is left hanging further down until you resize the
    browser a little.

    <html><head>
    <script>
    function resizenow(x){
    document.getEle mentById("div1_ inner").style.h eight=x+"px";
    }
    </script>
    </head><body>
    <form>
    <input type=button value="50" onclick="resize now(50)">
    <input type=button value="200" onclick="resize now(200)">
    </form>
    <div id="div1" style="display: block;backgroun d-color:yellow;">
    <div id="div1_inner " style="display: block;height:50 px;">
    <img width="100%" height="100%" src="" border="1">
    </div>
    </div>
    <div id="div2">Somet hing here</div>
    </body></html>
  • Jorge

    #2
    Re: Firefox2 problem with dynamic rendering (it's fine in IE, Safariand FF3)

    On Oct 3, 5:07 pm, Stevo <n...@mail.inva lidwrote:
    (...)
    >
    On the complex page, when you click on "200", then "div1" overlaps
    "div2" until you resize the browser a little bit. And when you click on
    "50", you see "div2" is left hanging further down until you resize the
    browser a little.
    try this:

    function resizenow (x) {
    var s= document.getEle mentById("div1_ inner").style;
    s.height= x+"px";
    s.display= "none";
    setTimeout(func tion () {
    s.display= "";
    },1);
    };

    --
    Jorge.

    Comment

    • Stevo

      #3
      Re: Firefox2 problem with dynamic rendering (it's fine in IE, Safariand FF3)

      Jorge wrote:
      On Oct 3, 5:07 pm, Stevo <n...@mail.inva lidwrote:
      >(...)
      >>
      >On the complex page, when you click on "200", then "div1" overlaps
      >"div2" until you resize the browser a little bit. And when you click on
      >"50", you see "div2" is left hanging further down until you resize the
      >browser a little.
      >
      try this:
      >
      function resizenow (x) {
      var s= document.getEle mentById("div1_ inner").style;
      s.height= x+"px";
      s.display= "none";
      setTimeout(func tion () {
      s.display= "";
      },1);
      };
      --
      Jorge.
      Thanks Jorge, I'll give that a try. It might produce an undesirable
      flicker, but if it works, it at least might lead to another potential
      solution. Perhaps I can add another 1 pixel high DIV in between div1 and
      div2 and toggle that one's display property.

      Comment

      • SAM

        #4
        Re: Firefox2 problem with dynamic rendering (it's fine in IE, Safariand FF3)

        Le 10/3/08 7:03 PM, Stevo a écrit :
        >
        Thanks Jorge, I'll give that a try. It might produce an undesirable
        flicker, but if it works, it at least might lead to another potential
        solution. Perhaps I can add another 1 pixel high DIV in between div1 and
        div2 and toggle that one's display property.

        an other soluce could be :

        function resizenow(x){
        var d = document.getEle mentById("div1_ inner");
        var c = d.cloneNode(tru e);
        c.style.height= x+"px";
        d.parentNode.re placeChild(c,d) ;
        }

        Not tested.

        Comment

        • sasuke

          #5
          Re: Firefox2 problem with dynamic rendering (it's fine in IE, Safariand FF3)

          On Oct 3, 9:34 pm, Jorge <jo...@jorgecha morro.comwrote:
          On Oct 3, 5:07 pm, Stevo <n...@mail.inva lidwrote:
          >
          (...)
          >
          On the complex page, when you click on "200", then "div1" overlaps
          "div2" until you resize the browser a little bit. And when you click on
          "50", you see "div2" is left hanging further down until you resize the
          browser a little.
          >
          try this:
          >
          function resizenow (x) {
            var s= document.getEle mentById("div1_ inner").style;
            s.height= x+"px";
            s.display= "none";
            setTimeout(func tion () {
                s.display= "";
            },1);
          >
          };
          Though it might just work, can I ask the reasoning behind this
          workaround? Is this is a known issue or does putting everything in
          setTimeout always seems to solve the issue? ;-)

          Comment

          • sasuke

            #6
            Re: Firefox2 problem with dynamic rendering (it's fine in IE, Safariand FF3)

            On Oct 3, 10:35 pm, SAM <stephanemoriau x.NoAd...@wanad oo.fr.invalid>
            wrote:
            Le 10/3/08 7:03 PM, Stevo a crit :
            >
            >
            >
            Thanks Jorge, I'll give that a try. It might produce an undesirable
            flicker, but if it works, it at least might lead to another potential
            solution. Perhaps I can add another 1 pixel high DIV in between div1 and
            div2 and toggle that one's display property.
            >
            an other soluce could be :
            >
            function resizenow(x){
               var d = document.getEle mentById("div1_ inner");
               var c = d.cloneNode(tru e);
               c.style.height= x+"px";
               d.parentNode.re placeChild(c,d) ;
            >
            }
            >
            Not tested.
            This might just be a little too memory expensive operation since you
            are creating a deep clone of the entire DIV tree; plus it is more work
            for the GC since you always end up discarding the previous DOM node.

            /sasuke

            Comment

            • Stevo

              #7
              Re: Firefox2 problem with dynamic rendering (it's fine in IE, Safariand FF3)

              Jorge wrote:
              On Oct 3, 5:07 pm, Stevo <n...@mail.inva lidwrote:
              >(...)
              >>
              >On the complex page, when you click on "200", then "div1" overlaps
              >"div2" until you resize the browser a little bit. And when you click on
              >"50", you see "div2" is left hanging further down until you resize the
              >browser a little.
              >
              try this:
              >
              function resizenow (x) {
              var s= document.getEle mentById("div1_ inner").style;
              s.height= x+"px";
              s.display= "none";
              setTimeout(func tion () {
              s.display= "";
              },1);
              };
              --
              Jorge.
              I have this example working now thanks to your suggestion. I didn't
              target the div1_inner for fear of seeing a flicker. Instead, I added a
              brand new extra DIV which is 0 pixels high, and I toggle that. It has
              the desired effect.

              If anyone wants to experience this bizarre behavior in Firefox 2, save
              this html in a file and try it. You can see how it works or doesn't
              work, depending on whether the return statement is commented out in the
              toggle function.

              I know that if I were to change the CSS (somehow) then this behavior
              would probably not be there, but I can't possibly change that. My only
              power to change anything is by JavaScript, and even then, I'm limited.
              If I were to change the CSS via JS, then there's a chance I would break
              the page layout.

              <html><head>
              <style>
              body{font:norma l 12px arial,helvetica ,sans-serif;position: relative;}
              #div4{float:lef t;position:stat ic;}
              </style>
              <script language="javas cript">
              function toggle()
              {
              return;
              var x=document.getE lementById('div 3').style.displ ay;
              document.getEle mentById('div3' ).style.display =x=='none'?'':' none';
              }
              function resize50(x)
              {
              document.getEle mentById("div1_ inner").style.h eight="50px";
              setTimeout(togg le,5);
              }
              function resize200(x)
              {
              document.getEle mentById("div1_ inner").style.h eight="200px";
              setTimeout(togg le,5);
              }
              </script>
              </head>
              <body>
              <form>
              <input type=button value="50" onclick="resize 50()">
              <input type=button value="200" onclick="resize 200()">
              </form>
              <div id="div1" style="display: block;backgroun d-color:yellow;wi dth:200px;">
              <div id="div1_inner " style="display: block;height:50 px;width:200px; ">
              <img width="100%" height="100%" src="" border="1">
              </div>
              </div>
              <div id="div2" style="display: block;backgroun d-color:red;width :200px;">
              <div id="div2_inner " style="display: block;height:50 px;width:200px; ">
              <img width="100%" height="100%" src="" border="1">
              </div>
              </div>
              <div id="div3"
              style="display: none;height:0px ;line-height:0px;font-size:0px;">
              </div>
              <div id="div4">
              <iframe width=100 height=100 frameborder=1 scrolling=yes></iframe>
              </div>
              </body>
              </html>

              Comment

              • sasuke

                #8
                Re: Firefox2 problem with dynamic rendering (it's fine in IE, Safariand FF3)

                On Oct 3, 9:34 pm, Jorge <jo...@jorgecha morro.comwrote:
                On Oct 3, 5:07 pm, Stevo <n...@mail.inva lidwrote:
                >
                (...)
                >
                On the complex page, when you click on "200", then "div1" overlaps
                "div2" until you resize the browser a little bit. And when you click on
                "50", you see "div2" is left hanging further down until you resize the
                browser a little.
                >
                try this:
                >
                function resizenow (x) {
                  var s= document.getEle mentById("div1_ inner").style;
                  s.height= x+"px";
                  s.display= "none";
                  setTimeout(func tion () {
                      s.display= "";
                  },1);
                >
                };
                Is there any reasoning here for using `setTimeout' or is this a known
                bug?

                Comment

                • sasuke

                  #9
                  Re: Firefox2 problem with dynamic rendering (it's fine in IE, Safariand FF3)

                  On Oct 3, 10:35 pm, SAM <stephanemoriau x.NoAd...@wanad oo.fr.invalid>
                  wrote:
                  Le 10/3/08 7:03 PM, Stevo a crit :
                  >
                  >
                  >
                  Thanks Jorge, I'll give that a try. It might produce an undesirable
                  flicker, but if it works, it at least might lead to another potential
                  solution. Perhaps I can add another 1 pixel high DIV in between div1 and
                  div2 and toggle that one's display property.
                  >
                  an other soluce could be :
                  >
                  function resizenow(x){
                     var d = document.getEle mentById("div1_ inner");
                     var c = d.cloneNode(tru e);
                     c.style.height= x+"px";
                     d.parentNode.re placeChild(c,d) ;
                  >
                  }
                  >
                  Not tested.
                  IMO this approach might become a bit memory intensive considering that
                  you are creating a deep copy of the DIV element which might have a lot
                  many children element objects. Plus to end up discarding the previous
                  copy of the node means more work for the GC.

                  /sasuke

                  Comment

                  • Jorge

                    #10
                    Re: Firefox2 problem with dynamic rendering (it's fine in IE, Safariand FF3)

                    On Oct 4, 7:35 am, sasuke <database...@gm ail.comwrote:
                    On Oct 3, 9:34 pm, Jorge <jo...@jorgecha morro.comwrote:
                    >
                    try this:
                    >
                    function resizenow (x) {
                      var s= document.getEle mentById("div1_ inner").style;
                      s.height= x+"px";
                      s.display= "none";
                      setTimeout(func tion () {
                          s.display= "";
                      },1);
                    >
                    };
                    >
                    Though it might just work, can I ask the reasoning behind this
                    workaround? Is this is a known issue or does putting everything in
                    setTimeout always seems to solve the issue? ;-)
                    Hehe. What happens is that the the page isn't rendered until after the
                    JS code has finished executing (except in chrome). Therefore, a way to
                    force a redraw in the middle of some code, is to break it up in two
                    halves, let the first half end and schedule the second half to run
                    some ms later via a setTimeout().

                    --
                    Jorge.

                    Comment

                    • sasuke

                      #11
                      Re: Firefox2 problem with dynamic rendering (it's fine in IE, Safariand FF3)

                      On Oct 6, 12:16 am, Jorge <jo...@jorgecha morro.comwrote:
                      On Oct 4, 7:35 am, sasuke <database...@gm ail.comwrote:
                      >
                      >
                      >
                      On Oct 3, 9:34 pm, Jorge <jo...@jorgecha morro.comwrote:
                      >
                      try this:
                      >
                      function resizenow (x) {
                        var s= document.getEle mentById("div1_ inner").style;
                        s.height= x+"px";
                        s.display= "none";
                        setTimeout(func tion () {
                            s.display= "";
                        },1);
                      >
                      };
                      >
                      Though it might just work, can I ask the reasoning behind this
                      workaround? Is this is a known issue or does putting everything in
                      setTimeout always seems to solve the issue? ;-)
                      >
                      Hehe. What happens is that the the page isn't rendered until after the
                      JS code has finished executing (except in chrome). Therefore, a way to
                      force a redraw in the middle of some code, is to break it up in two
                      halves, let the first half end and schedule the second half to run
                      some ms later via a setTimeout().
                      Fair enough, but how does this scenario apply to the original post? In
                      the very first post, the function `resizenow(x)' exits soon after
                      setting the height to `x' pixels, so ideally the change should be
                      reflected immediately [and yes, it does, except in FF2]. So the only
                      reason here would be that the refresh isn't happening. So to trigger a
                      refresh, after setting the required dimensions, we hide and show the
                      DIV, with the only different thing being the showing of DIV be placed
                      in a `setTimeout'. Am I correct here?

                      /sasuke

                      Comment

                      • Jorge

                        #12
                        Re: Firefox2 problem with dynamic rendering (it's fine in IE, Safariand FF3)

                        On Oct 6, 6:14 pm, sasuke <database...@gm ail.comwrote:
                        On Oct 6, 12:16 am, Jorge <jo...@jorgecha morro.comwrote:
                        >
                        >
                        >
                        >
                        >
                        On Oct 4, 7:35 am, sasuke <database...@gm ail.comwrote:
                        >
                        On Oct 3, 9:34 pm, Jorge <jo...@jorgecha morro.comwrote:
                        >
                        try this:
                        >
                        function resizenow (x) {
                          var s= document.getEle mentById("div1_ inner").style;
                          s.height= x+"px";
                          s.display= "none";
                          setTimeout(func tion () {
                              s.display= "";
                          },1);
                        >
                        };
                        >
                        Though it might just work, can I ask the reasoning behind this
                        workaround? Is this is a known issue or does putting everything in
                        setTimeout always seems to solve the issue? ;-)
                        >
                        Hehe. What happens is that the the page isn't rendered until after the
                        JS code has finished executing (except in chrome). Therefore, a way to
                        force a redraw in the middle of some code, is to break it up in two
                        halves, let the first half end and schedule the second half to run
                        some ms later via a setTimeout().
                        >
                        Fair enough, but how does this scenario apply to the original post? In
                        the very first post, the function `resizenow(x)' exits soon after
                        setting the height to `x' pixels, so ideally the change should be
                        reflected immediately [and yes, it does, except in FF2]. So the only
                        reason here would be that the refresh isn't happening. So to trigger a
                        refresh, after setting the required dimensions, we hide and show the
                        DIV, with the only different thing being the showing of DIV be placed
                        in a `setTimeout'. Am I correct here?
                        >
                        Yes, the div is hidden -JS code execution ends -a redraw takes
                        place -setTimeout times out and kicks in the code to show the div
                        again -code execution ends -another redraw cycle takes place...

                        --
                        Jorge.

                        Comment

                        Working...