Javascript jquery scrolltotop在除chrome之外的浏览器中不工作?
我在jquery中创建了一个滚动到顶部的函数。但除了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部分
<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')。动画(…);