我有一个用一些ES6编写的JavaScript块,用Babel编译。代码的目的是检查section
何时滚动到视图中,此时它添加的类在其内容中切换。我被告知这不适用于iOS9设备,我没有在这里测试自己复制错误。任何人都可以看到不支持这部分内容吗?我怀疑它会是classList.contains
,但我并不积极。任何建议都会很棒!
function toggleLume() {
const lumeImages = document.querySelectorAll('.model-image.lume');
lumeImages.forEach(image => image.classList.toggle('is-active'));
lumeIcons.forEach(icon => icon.classList.toggle('is-active'));
}
function checkIfInView() {
const windowHeight = window.innerHeight;
const windowTopPosition = window.scrollY;
const windowBottomPosition = (windowHeight + windowTopPosition);
const buffer = 120;
const panels = document.querySelectorAll('.panel');
panels.forEach(panel => {
const panelHeight = panel.clientHeight;
const panelTop = (panel.offsetTop - panel.scrollTop) + buffer;
const panelBottom = (panelTop + panelHeight);
if ((panelBottom >= windowTopPosition) && (panelTop <= windowBottomPosition) && !panel.classList.contains('in-view')) {
panel.classList.add('in-view');
}
});
}
旁注,如果我没有其他普通的JS选项,我首先对JavaScript解决方案和jQuery感兴趣。