You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将指定jQuery滚动事件代码转换为原生JavaScript代码?

对应原生JavaScript代码
window.addEventListener('scroll', function() {
  const paragraphs = document.querySelectorAll('.container p');
  const windowHeight = window.innerHeight;
  const breakPoint = windowHeight * 0.9;

  paragraphs.forEach(function(p) {
    const distance = p.getBoundingClientRect().top;

    if (distance > breakPoint) {
      p.classList.add('more-padding');
    }
    if (distance < breakPoint) {
      p.classList.remove('more-padding');
    }
  });
});

内容的提问来源于stack exchange,提问作者esovetnik

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 05:43:11