My element.style.top assignment is not working in Firefox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BClareS
    New Member
    • Jul 2007
    • 2

    My element.style.top assignment is not working in Firefox

    Sorry, I have found my mistake, but I cannot delete this post.
    I have discovered by experiment that element.style.t op assignment in IE works with just a number on the right but in Firefox you have to put the unit too. Original code is below. Adding "+'px'" made it work in Firefox too.
    Code:
    javascript
    	var fullsizeimage = document.getElementById('fullsizeimageframe');
    	if (!fullsizeimage) return false;
    	var coord = new Array(2);
    	coord = findPos(whichpic);
    	alert(coord[1]);
    	alert(fullsizeimage.offsetTop);
    	document.getElementById('fullsizeimageframe').style.top = coord[1]; 
    	alert(fullsizeimage.style.top);
      .....
    alert results IE: 162; -2; 162px (div moves)
    alert results Firefox 2: 162; 0; blank (div doesn't move)
    Last edited by BClareS; Jul 1 '07, 11:29 AM. Reason: solution found
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    hi ...

    i think you have to set explicitly:

    [CODE=javascript]ele_ref.style.t op = 'width px';[/CODE]

    so add + 'px' to your set-statement ...

    kind regards

    Comment

    • gits
      Recognized Expert Moderator Expert
      • May 2007
      • 5390

      #3
      congrats ;) you find it the same time for yourself ;)

      kind regards

      Comment

      • drhowarddrfine
        Recognized Expert Expert
        • Sep 2006
        • 7434

        #4
        Yes, units are required for html and css as the standard so states.

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Originally posted by BClareS
          Sorry, I have found my mistake, but I cannot delete this post.
          I'm sure this will help someone, so it makes sense not to delete it.

          Comment

          • akshalika
            New Member
            • Apr 2009
            • 17

            #6
            Hi friends,
            I have faced same issues.But it not work for me in FF. In bellow my code even if ScollTop greater than 0 it is not work


            Code:
             var ScrollTop = document.body.scrollTop;
                    if (ScrollTop == 0)
            
            {
            
                if (window.pageYOffset)
            
                    ScrollTop = window.pageYOffset;
            
                else
            
                    ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
            
            }
            
                    shadow.style.top = ScollTop +'px';
                    shadow.style.left = 0;
            Last edited by acoder; May 2 '09, 10:13 AM. Reason: Added [code] tags

            Comment

            • akshalika
              New Member
              • Apr 2009
              • 17

              #7
              Sorry Guys. it work me too

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Welcome to Bytes. Glad you managed to solve it. I assume the problem was a mis-spelling.

                PS. please remember to use [code] tags when posting code. Thanks.

                Comment

                • zshowing
                  New Member
                  • Jun 2014
                  • 1

                  #9
                  i registered just to say u saved my day.
                  a million thanks!

                  Comment

                  Working...