【发布时间】:2015-04-22 16:45:12
【问题描述】:
嘿 :) 我正在尝试在我网站上的每个页面之间制作淡入淡出效果,并在您单击重定向到给定网址的链接时实现淡出效果。但是在淡入淡出效果开始之前我得到了一些奇怪的闪烁效果。知道如何解决这个问题吗?
我使用的是无冲突包装器,因为我使用的是 Wordpress。
// Adding Wordpress Jquery selector($) support
jQuery(document).ready(function($) {
// Toggle hamburger menu for mobile devices
$(".menu-toggle").click(function(){
$(".main-navigation").toggleClass("navigation-toggle");
});
// Transition between pages
$(document).ready(function(){
// to fade in on page load
$("body").css("display", "none");
$("body").fadeIn(1500);
})
// delegate all clicks on "a" tag (links)
$(document).on("click", "a", function () {
// get the href attribute
var newUrl = $(this).attr("href");
// veryfy if the new url exists or is a hash
if (!newUrl || newUrl[0] === "#") {
// set that hash
location.hash = newUrl;
return;
}
// now, fadeout the html (whole page)
$("html").fadeOut(function () {
// when the animation is complete, set the new location
location = newUrl;
});
// prevent the default browser behavior.
return false;
});
});
【问题讨论】:
-
尝试删除
$("body").css("display", "none");
标签: jquery