我对此代码(https://codepen.io/MAJO-SEARCH/pen/gOOyWWb)有疑问。问题在于,第一次加载页面时,页面的页脚会被剪切掉,更改页面的宽度后,一切都会恢复正常。我不知道是怎么引起的。负责该脚本的脚本位于底部:
var lastPosition = 0;
var html = document.documentElement;
var body = document.body;
html.style.height = body.offsetHeight + 'px';
resizeHandler = function(){
html.style.height = body.offsetHeight + 'px';
}
window.addEventListener('resize',resizeHandler,false);
clickHandler = function(){
wrapper.style.height = smooth.offsetHeight + 'px';
window.scrollTo(0,offsetTop);
smooth.style.transform = 'translate3d(0px, -' + toggle.offsetTop + 'px, 0px)';
lastPosition = window.pageYOffset;
return false;
}
var scroll = window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.msRequestAnimationFrame ||
window.oRequestAnimationFrame ||
function(callback) {
window.setTimeout(callback, 1000 / 60)
};
function loop() {
if (lastPosition == window.pageYOffset) {
scroll(loop);
return false;
} else lastPosition = window.pageYOffset;
body.style.transform = 'translate3d(0px, -' + lastPosition + 'px, 0px)';
scroll(loop);
return true;
}
body.addEventListener('scroll',loop,true);
loop();