基于视口可见性的 Javascript 功能适用于桌面,但不适用于智能手机?

时间:2020-12-29 20:44:39

标签: javascript bounding

我在网站上使用的某些 Javascript 有问题。 目的是根据特定 div 的屏幕外观更改标题元素 css。 实际上它在桌面上完美运行!但不是在iPhone上... 我无法弄清楚它有什么问题...... 你能帮我理解这个吗? 非常感谢!

var isInViewport = function (elem) {
    var bounding = elem.getBoundingClientRect();
    return (
        bounding.top >= 0 &&
        bounding.left >= 0 &&
        bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
        bounding.right <= (window.innerWidth || document.documentElement.clientWidth)
    );
};
var section_clouds = document.querySelector('#section_intro_clouds');
window.addEventListener('transitionend', function (event) {
    if (isInViewport(section_clouds)) {
        document.getElementById('header_blanc').classList.add('colorer_bleu');}
else {document.getElementById('header_blanc').classList.remove('colorer_bleu');}
}, false);

0 个答案:

没有答案