chrome上的Jquery width()函数给出了加载和重载时的不同值(F5)

我不知道发生了什么,但我有这样的菜单设置

 

问题是div.puntero是一个div,当它hover在不同的indice_item上时跟随鼠标。 我用jquery做它,它的function是动画的。 当页面加载时会创建这个div.puntero,它会查找此菜单的第一项并获取宽度和顶部和左侧坐标,因此它可以在具有类activo的项目下设置div.puntero。

这是执行此操作的代码

 /* * Seleccionado el primero activo */ $(document).ready(function() { $('div.indice_item').last().after('
 
'); //seteamos el puntero donde debe estar ancho=$('div.indice_item').first().width() alert(ancho); $('#puntero').width($('div.indice_item').first().width()); $('#puntero').height(($('div.indice_item').first().height()+3)); $('#puntero').css({ "top" : $('div.indice_item').position().top, "left" : $('div.indice_item').position().left }); $('.indice_item').each(function (){ //$(this). }); });

这在firefox中完美运行,但在chrome中我有几个问题,它似乎工作正确。 但后来我按下重装或F5并且div.puntero的宽度变得疯狂。 我添加了警报(ancho); 对于宽度,当我进入页面时,它给我正确的宽度180,当我按下重新加载1665或1649时,图表。 为什么它这样工作?

尝试在加载所有东西后设置高度和宽度,即使用$(window).load(function() {//set height and width here});

我相信它似乎在firefox中运行正常,因为缓存。 也许我错了,只是设置jsFiddle。 指出问题要容易得多。

这是解决方案,

在Chrome中页面刷新(F5)之后,jQuery表现得很奇怪

用这个

$(window).load(function(){});

而不是:

$(document).ready(function(){});