[英]Scroll to top Jquery not working
So I've been looking all over for this and the only thing that worked was to replace in CSS of the body height: 100%
for min-height: 100%
. 因此,我一直在寻找这些东西,唯一有效的方法是替换CSS的
height: 100%
min-height: 100%
。 The thing is that change breaks the styling of the page. 关键是更改会破坏页面的样式。 Is there another workaround for this?
还有其他解决方法吗?
function ScrollTop() {
$('html, body').animate({ scrollTop: 0 }, 0);
return false;
}
function NextPage(page) {
$(".page[data-page='" + page + "']").addClass("hidden");
page = page + 1;
$(".page[data-page='" + page + "']").removeClass("hidden");
ScrollTop();
}
html, body, form, #container, #mainform, #content {
margin: 0 auto;
padding: 0;
position: relative !important;
width: 100% !important;
height: 100% !important;
}
Just FYI this is not working in any browser (latest version of all browsers to date). 仅供参考,这不适用于任何浏览器(迄今为止所有浏览器的最新版本)。 Also try removing
overflow-x: hidden
from the body and still wasn't working. 另外,请尝试清除
overflow-x: hidden
从身体overflow-x: hidden
但仍然无法正常工作。 Also tried 也尝试过
$("#container").animate({
scrollTop:0
}, "slow");
window.scrollTo(0, 0) //this returns undefined
I have created a working fiddle. 我创造了一个工作的小提琴。 It is working just fine.
运行正常。
$(function() {
$('.backtotop').click(function()
$('body').animate({ scrollTop: 0 }, .2);
return false;
});
});
This should work https://jsfiddle.net/cmhLroe1/ 这应该工作https://jsfiddle.net/cmhLroe1/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.