javascript - jquery动画到新页面

标签 javascript jquery ajax jquery-animate

有没有办法使用 jquery.animate 通过 ajax 加载页面,并在准备好时将其动画化以向上或向侧面滑动?因此,假设我在index.html页面中,并且我想要转到about.html页面,它会首先加载它,当它准备好而不是刷新到新页面时,它将使用以下方法对其进行动画处理:http://demos.flesler.com/jquery/localScroll/#section4c

function(){
$("#go2About").click(function(){
    $('about.html').animate({
         //animate the new page here
    });
});

这将是某种动画示例代码

最佳答案

你可以使用类似这样的逻辑:

<!DOCTYPE>

<html>
<head>
    <title>Test</title>

    <script type="text/javascript">
        function loadIt() {
            $.ajax({
                url: "about.html",
                cache: false,
                success: function (data) {
                    $("#content").empty();
                    $(data).hide().appendTo($("#content")).slideDown();
                },
                error: function () {
                    alert("something went wrong");
                }
            });
        }
    </script>
</head>
<body>
    <input type="button" id="button1" value="Load About" onclick="loadIt();" />

    <br />

    <div id="content" style="width: 400px; height: 400px; border: 1px solid #000;">

    </div>
</body>
</html>

但要知道“about.html”的内容不应该是完整的 HTML 文档 - 它应该是进入 元素的内容。

一个更简单的方法可能是使用 iframe(当它没有任何内容时隐藏) - 当您单击按钮时,让 javascript 将 iframe 的 src 属性设置为“about.html”,然后使用 slipDown() 来动画它被“加载”。这样,“about.html”就可以是一个完整的 HTML 文档,您不必担心类似的问题。

关于javascript - jquery动画到新页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10938388/

相关文章:

PHP MySQL & AJAX 搜索过滤时间延迟

PHP/AJAX 图像抓取脚本类似于 Facebook 消息传递功能

javascript - 按钮点击伪装

javascript - 自己的 JavaScript 没有运行

php - 重新加载页面时重新填充表单的最简单方法是什么?

jquery - jqGrid 寻呼机文本框大小

javascript - 使用可拖动的 jQuery 函数

javascript - 标准功能在网络 worker 中不起作用

javascript - 以 javascript (jquery) 中的 track div class 和 data-id =""为例

jquery - .ajaxStart 和 .ajaxStop 未触发