469,277 Members | 1,923 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,277 developers. It's quick & easy.

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.top 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.
Expand|Select|Wrap|Line Numbers
  1. javascript
  2.     var fullsizeimage = document.getElementById('fullsizeimageframe');
  3.     if (!fullsizeimage) return false;
  4.     var coord = new Array(2);
  5.     coord = findPos(whichpic);
  6.     alert(coord[1]);
  7.     alert(fullsizeimage.offsetTop);
  8.     document.getElementById('fullsizeimageframe').style.top = coord[1]; 
  9.     alert(fullsizeimage.style.top);
  10.   .....
alert results IE: 162; -2; 162px (div moves)
alert results Firefox 2: 162; 0; blank (div doesn't move)
Jul 1 '07 #1
8 20426
gits
5,390 Expert Mod 4TB
hi ...

i think you have to set explicitly:

Expand|Select|Wrap|Line Numbers
  1. ele_ref.style.top = 'width px';
so add + 'px' to your set-statement ...

kind regards
Jul 1 '07 #2
gits
5,390 Expert Mod 4TB
congrats ;) you find it the same time for yourself ;)

kind regards
Jul 1 '07 #3
drhowarddrfine
7,435 Expert 4TB
Yes, units are required for html and css as the standard so states.
Jul 1 '07 #4
acoder
16,027 Expert Mod 8TB
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.
Jul 2 '07 #5
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


Expand|Select|Wrap|Line Numbers
  1.  var ScrollTop = document.body.scrollTop;
  2.         if (ScrollTop == 0)
  3.  
  4. {
  5.  
  6.     if (window.pageYOffset)
  7.  
  8.         ScrollTop = window.pageYOffset;
  9.  
  10.     else
  11.  
  12.         ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
  13.  
  14. }
  15.  
  16.         shadow.style.top = ScollTop +'px';
  17.         shadow.style.left = 0;
May 2 '09 #6
Sorry Guys. it work me too
May 2 '09 #7
acoder
16,027 Expert Mod 8TB
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.
May 2 '09 #8
i registered just to say u saved my day.
a million thanks!
Jun 29 '14 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Jeff Gutsell | last post: by
8 posts views Thread by Sunny | last post: by
15 posts views Thread by Sunny | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.