将上面的代码去除注释一次性输出

动态 未结 0 99
小小草
小小草 LV1 2023年9月23日 23:40 发表
```javascript const fixedDiv = document.querySelector('.fixed'); const contentDiv = document.querySelector('.content'); let isFixed = false; let fixedDivHeight = 0; window.addEventListener('scroll', () => { const scrollPosition = window.scrollY; if (scrollPosition >= contentDiv.offsetTop && !isFixed) { fixedDivHeight = fixedDiv.offsetHeight; fixedDiv.style.position = 'static'; fixedDiv.style.height = `${fixedDivHeight}px`; fixedDiv.style.position = 'fixed'; fixedDiv.style.top = '0'; fixedDiv.style.left = '0'; fixedDiv.style.width = '100%'; isFixed = true; } if (scrollPosition < contentDiv.offsetTop && isFixed) { fixedDiv.style.height = `${fixedDivHeight}px`; fixedDiv.style.position = 'static'; fixedDiv.style.top = 'auto'; fixedDiv.style.left = 'auto'; fixedDiv.style.width = 'auto'; isFixed = false; } }); ```
收藏(0)  分享
相关标签: 智能问答
问题没解决?让AI助手帮你作答 AI助手
0个回复
  • 消灭零回复