為了改善您的使用體驗,本網站正在進行維護,部分功能暫時無法使用。若本站的文件無法解決您的問題,想要向社群發問的話,請到 Twitter 上的 @FirefoxSupport 或 Reddit 上的 /r/firefox 發問,我們的社群成員將很快會回覆您的疑問。

搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

了解更多

Creating a new img element and cannot change style.left or style.top to set placement as I can in other browsers

  • 3 回覆
  • 1 有這個問題
  • 5 次檢視
  • 最近回覆由 Svetlana

more options

I create a new element of type img and am placing in a specific absolute position by setting style.position, style.left and style.top attributes. Works fine in IE and Opera but FF does not allow me to modify any of the style attributes either before or after the element is inserted into the document. I've tested this with 3.5.9 and 3.6.3 and both have the problem.

This happened

Every time Firefox opened

== upon install of FF

I create a new element of type img and am placing in a specific absolute position by setting style.position, style.left and style.top attributes. Works fine in IE and Opera but FF does not allow me to modify any of the style attributes either before or after the element is inserted into the document. I've tested this with 3.5.9 and 3.6.3 and both have the problem. == This happened == Every time Firefox opened == upon install of FF

所有回覆 (3)

more options

I want to ask for more information. Could you pastebin your code?

more options

Are you including units in your values?

more options

I knew it was something incredibly obvious that I was missing.

by doing

               himg.style.left = (Math.floor(coords[0]) + tweeks.x) + "px";
               himg.style.top = (Math.floor(coords[1]) + tweeks.y) + "px";

instead of

               himg.style.left = Math.floor(coords[0]) + tweeks.x;
               himg.style.top = Math.floor(coords[1]) + tweeks.y;

it works. It seems Opera and IE assume px if nothing supplied while FF needs it explicitly specified.

Thanks!