'移动端' : 'PC端', 'Header高度:', headerHeight, '设置padding:', paddingValue); } // 滚动处理函数 function handleScroll() { // 如果是移动端,header固定不动 if (isMobile) { $header.css('transform', 'translateY(0)'); return; } const currentScrollTop = $(window).scrollTop(); const headerHeight = $header.outerHeight(); const hideHeight = headerHeight / 5; // 隐藏1/5高度 // PC端:判断滚动方向 if (currentScrollTop > lastScrollTop && currentScrollTop > 50) { // 向下滚动:隐藏1/5高度 $header.css('transform', `translateY(-${hideHeight}px)`); } else { // 向上滚动:回到原位 $header.css('transform', 'translateY(0)'); } lastScrollTop = currentScrollTop <= 0 ? 0 : currentScrollTop; } // 初始设置 setBodyPadding(); // 页面加载后设置 $(window).on('load', function() { setTimeout(setBodyPadding, 100); setTimeout(setBodyPadding, 500); }); // 窗口大小改变时重新计算 $(window).on('resize', function() { setTimeout(function() { setBodyPadding(); // 重置滚动位置 lastScrollTop = $(window).scrollTop(); // 重新判断设备类型 isMobile = $(window).width() <= 768; // 重置transform if (isMobile) { $header.css('transform', 'translateY(0)'); } }, 150); }); // 监听滚动事件 let ticking = false; $(window).on('scroll', function() { if (!ticking) { window.requestAnimationFrame(function() { handleScroll(); ticking = false; }); ticking = true; } }); // 初始滚动状态 handleScroll(); // 调试信息 $(window).on('load', function() { console.log('初始化完成:', isMobile ? '移动端模式' : 'PC端模式'); console.log('窗口宽度:', $(window).width(), 'Header高度:', $header.outerHeight()); }); });
联系我们
020-87392339

手机:18998295273微信同号

手机:18998295272微信同号

邮箱:1061717801@qq.com

地址:广州市越秀区环市东水荫路2号

企业分站:北京 天津 河北 山西 内蒙古 辽宁 吉林 黑龙江 上海 江苏 浙江 安徽 福建 江西 山东 河南 湖北 湖南 广东 广西 海南 重庆 四川 贵州 云南 西藏 陕西 甘肃 青海 宁夏 新疆 更多分站
在线客服
联系方式

手机电话(微信同号)

18998295272

手机电话(微信同号)

18998295273

固定电话(10条线)

020-87392339

扫一扫加微信
线