jquery - 使用 jquery 淡出整个页面

标签 jquery html fadeout fading

因此,当用户转到我网站的另一部分时,我试图淡出该页面。在阅读了一些关于堆栈溢出的内容之后,我编写了以下代码。但它看起来很乱/丑陋。是否有适当的方法来淡出网页,或者这一切都是 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/

相关文章:

php - 如何切换具有 php 值的 div 内容

javascript - 谁能给我一个信息窗口内 div 元素的 jquery 动画示例代码?

javascript - 当窗口小于 ~650px 时,Owl Carousel 不居中

javascript - 每 x 秒循环一次脚本

javascript - mousemove 获取嵌套元素的 XY 偏移量

jquery - 我的简单 jQuery fadeOut 不工作

javascript - 重置 SetInterval 以在另一个 ID 上重复该功能

javascript - 如何在 jQuery 中制作 3 个动画并循环播放它们? (时间安排错了。)

javascript - 根据点击次数不同的事件

html - 菜单的子菜单在 Chrome 中不起作用(位置为 : absolute) 的东西