Chrome和Firefox忽略Javascript样式的顶部和左侧

Chrome和Firefox忽略Javascript样式的顶部和左侧,javascript,html,css,google-chrome,safari,Javascript,Html,Css,Google Chrome,Safari,我正在使用Javascript中的一些样式,并尝试在我想要的地方放置一些div。这段代码在Safari中非常有效,每个div都放在左侧和顶部,但在Chrome和Firefox上不起作用。这不是问题所在 div = document.createElement('div'); div.id = this.numberOfSystem + 'circle' + i; div.x = ((this.centerX) + ((this.lenghtMain/2 + this.

我正在使用Javascript中的一些样式,并尝试在我想要的地方放置一些div。这段代码在Safari中非常有效,每个div都放在左侧和顶部,但在Chrome和Firefox上不起作用。这不是问题所在

    div = document.createElement('div');
    div.id = this.numberOfSystem + 'circle' + i;


    div.x = ((this.centerX) + ((this.lenghtMain/2 + this.lenghtSmall/2 + 50) * Math.sin( 2 * Math.PI / this.amount * i))) - (this.lenghtSmall / 2);  
    div.y = ((this.centerY) + ((this.lenghtMain/2 + this.lenghtSmall/2 + 50) * Math.cos( 2 * Math.PI / this.amount * i))) - (this.lenghtSmall / 2);

    div.style.position = "fixed";
    div.style.left = div.x + "px";
    div.style.top = div.y + "px";
    div.style.width = this.lenghtSmall;
    div.style.height = this.lenghtSmall;
Chrome和Firefox的问题是,当我签入开发工具style.top和style.left时,没有定义,因此所有元素都显示在左上角。从开发者工具->元素中我得到了这个

<div id="0circle1" style="position: fixed; width: 250px; height: 250px; text-align: center; background-image: url(file:///Users/Imanol/Documents/Webs/Portfolio2/circulo200.png); background-size: 100%;"><div style="margin: 20%;">Curriculum</div></div>
左上角什么都没有。。。在Safari中,它可以完美地工作,元素被放置在它们想要的地方。这是我从狩猎中得到的

<div id="0circle0" style="position: fixed; left: 340.0003905596077px; top: 360.04122042944215px; width: 250px; height: 250px; background-image: url(file:///Users/Imanol/Documents/Webs/Portfolio2/circulo200.png); background-size: 100%; text-align: center;"><div style="margin: 20%;">Studies<br><br><img width="100" height="100" src="pastel.jpg"></div></div>
我试过数学,但还是不行。

解决了


问题来自使用document.width和document.height计算的this.centerX和this.centerY,它们在safari中有效,但在firefox或chrome中无效,因此在这两个版本中,它们返回了NaN。。。我把它们改成了window.innerWidth和window.innerHeight,到处都很完美。。。谢谢大家!

如果在代码中设置断点,div.x和div.y的值是多少?chrome和firefox都有开发者模式,因此您可以在代码中轻松设置断点。这指的是什么?你能给我们看一下全部相关代码吗?好的!断点帮助我找到了错误。。。我不认为这可能是计算div.x和div.x的错误,所以我从未检查过它们的值。。。问题来自使用document.width和document.height计算的this.centerX和this.centerY,它们在safari中有效,但在firefox或chrome中无效,因此在这两个版本中,返回的NaN。。。我把它们改成了window.innerWidth和window.innerHeight,到处都很完美。。。非常感谢。所以,回答你自己的问题……是的,你可以回答你自己的问题: