Мой заголовок немного глючит, и он ломается, если страница загружается на полпути вниз (если она связана w/a # в конце URL-адреса) или если вы просматриваете, пока отображается загрузчик.
Как использовать JS для отключения прокрутки во время загрузки страницы и принудительной загрузки страницы на самом верху.
благодаря
// First you load the page at the top by adding a simple # at the end
$(document).ready(function() {
var url = window.location.href;
console.log(url);
if( url.indexOf('#') < 0 ) {
window.location.replace(url + "#");
} else {
window.location.replace(url);
}
});
//Freeze page content scrolling while the page is loading
$(document).ready(function() {
if($("html").css("position") != "fixed") {
var top = $("html").scrollTop() ? $("html").scrollTop() : $("body").scrollTop();
if(window.innerWidth > $("html").width()) {
$("html").css("overflow-y", "scroll");
}
$("html").css({"width": "100%", "height": "100%", "position": "fixed", "top": -top});
}
});
//Unfreeze page content scrolling when the page has finished loading
$(window).load(function() {
if($("html").css("position") == "fixed") {
$("html").css("position", "static");
$("html, body").scrollTop(-parseInt($("html").css("top")));
$("html").css({"position": "", "width": "", "height": "", "top": "", "overflow-y": ""});
}
});
Вы можете попробовать следующее:
$(document).ready(function(){
$(this).scrollTop(0);
});