Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jquery scrolltotop在除chrome之外的浏览器中不工作?_Javascript_Jquery_Html_Google Chrome - Fatal编程技术网

Javascript jquery scrolltotop在除chrome之外的浏览器中不工作?

Javascript jquery scrolltotop在除chrome之外的浏览器中不工作?,javascript,jquery,html,google-chrome,Javascript,Jquery,Html,Google Chrome,我在jquery中创建了一个滚动到顶部的函数。但除了chrome之外,它在浏览器中不起作用。请帮忙 样式部分: <style> #gototop { cursor: pointer; bottom:100px; position:fixed; right:0; z-index:90000000; } </style> #戈托普{ 光标:指针; 底部:100px; 位置:固定; 右:0; z指数:90000000; } Html部分

我在jquery中创建了一个滚动到顶部的函数。但除了chrome之外,它在浏览器中不起作用。请帮忙

样式部分:

  <style>
  #gototop {
  cursor: pointer;
  bottom:100px;
  position:fixed;
  right:0;
  z-index:90000000;
  }
  </style>

#戈托普{
光标:指针;
底部:100px;
位置:固定;
右:0;
z指数:90000000;
}
Html部分:

<div id="gototop"><img src="gototop.png"></div>

脚本部分:

<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script>
(function(){

    var pstatic = $(window).width()/4;

    $('#gototop').fadeOut(05);

    $(window).scroll(function(){
        var pcurrent = $(this).scrollTop();
        (pcurrent <= pstatic) ? $('#gototop').fadeOut(500) : $('#gototop').fadeIn(500);
    })

    $("#gototop").on("click",function(){
            $('body').animate({scrollTop:0}, 1000, 'swing');
    });

})();
</script>

(功能(){
var pstatic=$(窗口).width()/4;
$(#gotop')。淡出(05);
$(窗口)。滚动(函数(){
var pccurrent=$(this.scrollTop();

(p当前您必须使用
body
html
标记上的animate功能,以确保它在所有浏览器中都能工作

$("#gototop").on("click",function(){
    $('body,html').animate({scrollTop:0}, 1000, 'swing');
});
$('html,body')。动画(…);