Проблемы с прокруткой на Mac OS - PullRequest
0 голосов
/ 02 января 2019

Итак, я написал сценарий для своего веб-сайта портфолио, чтобы перейти к разделу по индексу.Он работает на всех протестированных браузерах и смартфонах, но на устройствах Mac он не работает, вероятно, вместо этого, чтобы перейти к следующим разделам, он автоматически переходит ко второму следующему разделу.

Надеюсь, кто-то может мне помочь.

var anchorPoints = [];
var anchorLocation = [];
var anchorIndex = 0;
var waiting = false;
var canScroll = true;
var offset = 0

window.onload = function () {
    anchorPoints = document.getElementsByClassName("js-anchor");

    for (i = 0; i < anchorPoints.length; i++) {
        getLocation = anchorPoints[i].getBoundingClientRect();
        getLocation = getLocation.top - offset;

        anchorLocation.push(parseInt(getLocation));
    }
}

$(document).on('mousewheel DOMMouseScroll', function (e) {
    if (detectMobile() == true) {
        return;
    }
    if ((waiting || canScroll == false)) {
        return;
    }
    e.preventDefault();//prevent the default mousewheel scrolling
    var active = $('section.active');
    var delta = e.originalEvent.detail < 0 || e.originalEvent.wheelDelta > 0 ? 1 : -1;
    waiting = true;
    if (delta < 0) {
        anchorIndex += 1;
        if (anchorIndex > (anchorPoints.length - 1)) {
            anchorIndex = 0;
        } 
        scrollTo({
            top: anchorLocation[anchorIndex],
            left: 0,
            behavior: 'smooth'
        });

        console.log(anchorIndex);
        console.log('scrolling down');
    } else {
        anchorIndex -= 1;
        if (anchorIndex < 0) {
            anchorIndex = anchorPoints.length - 1;

        }
        scrollTo({
            top: anchorLocation[anchorIndex],
            left: 0,
            behavior: 'smooth'
        });
        console.log(anchorIndex);
        console.log('scrolling up');
    }
    setTimeout(function () {
        waiting = false;
    }, 1000);
});
...