2
问题是,当新的页面加载(选定的菜单项应完全集中的菜单是http://maartenbrakkee.nl/portfolio/和使用代码我的菜单跳跃:菜单页面加载后跳转
$(document).ready(function(){
/* Menu klik animatie II */
$("nav#menu a").click(function(e) {
e.preventDefault();
var dit = $(this);
$(this).parent().siblings().removeClass("current_page_item");
$(this).parent().addClass("current_page_item");
geselecteerd = $('#menu li.current_page_item').sumOuterWidth(true);
voor = $('#menu li.current_page_item').prevAll().sumOuterWidth(true);
vader = $('#menu').parent().width();
invoegen = parseInt(((vader-geselecteerd)/2)-voor);
$('nav#menu').prev().animate({
width: invoegen + 'px',
}, {
duration: 400,
specialEasing: {
width: 'linear',
height: 'easeOutBounce'
},
complete: function() {
$('#content').fadeTo('fast', 0.01, function() {
document.location = $(dit).attr('href');
});
}
});
});
/* Menu uitlijning: geselecteerde item centraal */
$.fn.sumOuterWidth = function(useMargins) {
var sum = 0;
this.each(function() {
sum += $(this).outerWidth(useMargins);
});
return sum;
};
geselecteerd = $('#menu li.current_page_item').sumOuterWidth(true);
voor = $('#menu li.current_page_item').prevAll().sumOuterWidth(true);
vader = $('#menu').parent().width();
invoegen = parseInt(((vader-geselecteerd)/2)-voor);
$('#menu').before("<div style='width:" + invoegen + "px;float:left'> </div>");
});
我不能真的认为我做错了;宽度(从菜单之前的div)应该与动画的宽度(在新页面加载之前)和新加载的页面上的宽度相同。当我使用不同的字体(Varela Round - > Google网络字体)时,它不会发生。
也许试着在你的代码中包装它? $(window).load(function(){// code}); – hagope 2012-04-13 00:45:50
off off!日Thnx – Waarten 2012-04-14 10:21:01