Javascript JQuery页面滚动动画仅适用于chrome

Javascript JQuery页面滚动动画仅适用于chrome,javascript,jquery,html,google-chrome,Javascript,Jquery,Html,Google Chrome,我有以下两个html文件。当您单击第一页(a.html)中的链接时,它将打开第二页(b.html)并向下滚动到相关位置。我已经在卷轴上添加了JQuery动画。这在chrome浏览器中非常有效,但在firefox和IE等其他浏览器中则不行 a、 html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.

我有以下两个html文件。当您单击第一页(a.html)中的链接时,它将打开第二页(b.html)并向下滚动到相关位置。我已经在卷轴上添加了JQuery动画。这在chrome浏览器中非常有效,但在firefox和IE等其他浏览器中则不行

a、 html

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>




    </head>

    <body>

       <a href="b.html#elementID">Jump</a>

</body>
</html>

无标题文件
b、 html

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('html, body').hide();

        if (window.location.hash) {
            setTimeout(function() {
                $('html, body').scrollTop(0).show();
                $('html, body').animate({
                    scrollTop: $(window.location.hash).offset().top
                    }, 1000)
            }, 0);
        }
        else {
            $('html, body').show();
        }
    });
</script>


</head>

<body>





<div style="margin-top:4000px" id="elementID">AAAAAAAAAAAAA</div>
<h1>AAAAAAA</h1>
<h1>AAAAAAA</h1>
<h1>AAAAAAA</h1>
<h1>AAAAAAA</h1>
<h1>AAAAAAA</h1>
<h1>AAAAAAA</h1>
<h1>AAAAAAA</h1>
<h1>AAAAAAA</h1>
<h1>AAAAAAA</h1>
<h1>AAAAAAA</h1>
<h1>AAAAAAA</h1>
<h1>AAAAAAA</h1>
<h1>AAAAAAA</h1>
<h1>AAAAAAA</h1>
<h1>AAAAAAA</h1>
<h1>AAAAAAA</h1>

</body>
</html>

无标题文件
$(文档).ready(函数(){
$('html,body').hide();
if(window.location.hash){
setTimeout(函数(){
$('html,body').scrollTop(0.show();
$('html,body')。设置动画({
scrollTop:$(window.location.hash).offset().top
}, 1000)
}, 0);
}
否则{
$('html,body').show();
}
});
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
AAAAAAAA
AAAAAAAA
AAAAAAAA
AAAAAAAA
AAAAAAAA
AAAAAAAA
AAAAAAAA
AAAAAAAA
AAAAAAAA
AAAAAAAA
AAAAAAAA
AAAAAAAA
AAAAAAAA
AAAAAAAA
AAAAAAAA
AAAAAAAA
试试这个。。 您必须在页面加载数据后滚动

if (window.location.hash) {
     $('html, body').show();
      $('html, body').animate({ scrollTop: $('html, body')[0].scrollHeight }, 1000);

     }

默认情况下,Firefox强制浏览器转到哈希标记的位置。您需要在页面加载时重置
scrollTop
,然后制作如下动画:

$(document).ready(function() {
        $('html, body').hide();

        if (window.location.hash) {
            setTimeout(function() {
                $('html, body').scrollTop(0).show();
                $('html, body').prop('scrollTop',0).animate({
                    scrollTop: $(window.location.hash).offset().top
                    }, 1000)
            }, 0);
        }
        else {
            $('html, body').show();
        }
    });