Update index.js

This commit is contained in:
路人甲 2024-08-03 02:55:15 +08:00
parent 9c19981052
commit a4699825ca

View File

@ -1,9 +1,8 @@
// 头部滚动 // 头部滚动
(function(){ (function(){
let $header = document.querySelector('.mod-head'); let $header = document.querySelector('header');
document.querySelector('.scroll-container').addEventListener('scroll',function(){ document.querySelector('.scroll-container').addEventListener('scroll',function(){
let scrollTop = this.scrollTop; let scrollTop = this.scrollTop;
console.log('[scrollTop]',scrollTop);
let ratio = Math.min(scrollTop/1000,1); let ratio = Math.min(scrollTop/1000,1);
$header.style.background = 'rgba(255,255,255,'+(ratio*0.8)+')'; $header.style.background = 'rgba(255,255,255,'+(ratio*0.8)+')';
$header.style.boxShadow = '1px 1px 6px rgba(0,0,0,'+(ratio*0.1)+')'; $header.style.boxShadow = '1px 1px 6px rgba(0,0,0,'+(ratio*0.1)+')';
@ -12,20 +11,13 @@
// 底部滚动 // 底部滚动
(function(){ (function(){
let timer = null;
let $gotop = document.querySelector('.mod-fixedbar .gotop'); let $gotop = document.querySelector('.mod-fixedbar .gotop');
let $container = document.querySelector('.scroll-container');
$gotop.addEventListener('click',function(){ $gotop.addEventListener('click',function(){
cancelAnimationFrame(timer); $container.scrollTo({
let scrollTop = document.body.scrollTop || document.documentElement.scrollTop; left:0,
let move = scrollTop/18; top:0,
timer = requestAnimationFrame(function fn(){ behavior:'smooth'
var oTop = document.body.scrollTop || document.documentElement.scrollTop;
if(oTop > 0){
document.body.scrollTop = document.documentElement.scrollTop = oTop - move;
timer = requestAnimationFrame(fn);
}else{
cancelAnimationFrame(timer);
}
}); });
}); });
})(); })();