因此,当用户转到我网站的另一部分时,我试图淡出该页面。在阅读了一些关于堆栈溢出的内容之后,我编写了以下代码。但它看起来很乱/丑陋。是否有适当的方法来淡出网页,或者这一切都是 hacky?似乎(目前)我的页面在它有机会淡出之前就被丢弃了。
<link rel="stylesheet" href="http://www.catlard.com/styles/body.css" type="text/css"/>
<link rel="icon" href="http://www.catlard.com/caticon.ico" />
<link rel="shortcut icon" href="http://www.catlard.com/caticon.ico?v=2" />
<script src="http://code.jquery.com/jquery-latest.min.js" charset="utf-8"> </script>
<script type="text/javascript">
$(document).ready( function(){
$("html").hide();
$("html").delay(250).fadeIn();
$(window).unload(function () {
$("html").fadeOut();
});
});
</script>
最佳答案
对 document
或 "html"
使用 fadeOut()
jQuery 函数:
$(document).fadeOut();
或
$("html").fadeOut();
阅读您的评论后,我了解到您想在单击链接时淡出页面。
不要使用 $(window).unload
但要检测链接上的点击事件并手动设置位置以防止默认浏览器行为。
// 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;
});
关于jquery - 使用 jquery 淡出整个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19397515/