出于某种原因$("...").width()
,在文档准备好后立即返回错误的值。
我看到了这些值:
文件准备好后立即:
$(document).ready(function(){
$("li.active a").width() //returns 76 - incorrect
});
$(document).ready(function(){
$(window).load(function(){
$("li.active a").width() //returns 59 - the correct value
});
});
$(document).ready(function(){
setTimeout(function(){
$("li.active a").width() //returns 59 - the correct value
}, 100);
});
我正在获取 wordpress 菜单项的宽度并调整它们的大小,以便它们始终适合我的响应式设计。没有应该导致此更改的图像或资产。
更新 见下面我的评论。原来有一个资产,一种嵌入的字体,需要一秒钟才能加载。