Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/415.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么我的javascript dispatchEvent不工作_Javascript_Dispatchevent - Fatal编程技术网

为什么我的javascript dispatchEvent不工作

为什么我的javascript dispatchEvent不工作,javascript,dispatchevent,Javascript,Dispatchevent,下面是我的javascript代码。上一页和下一页使用HTML按钮元素工作正常。 但我不知道为什么addEventListener(“轮子”)不起作用。所以我插入了一些console.log,然后我意识到var delta是正确的。但是,我想有一个问题是“如果(δ~~”区域 const pageList = document.querySelectorAll('.verticalPaging'); const previousPage = document.querySelector('#pre

下面是我的javascript代码。上一页和下一页使用HTML按钮元素工作正常。 但我不知道为什么addEventListener(“轮子”)不起作用。所以我插入了一些console.log,然后我意识到var delta是正确的。但是,我想有一个问题是“如果(δ~~”区域

const pageList = document.querySelectorAll('.verticalPaging');
const previousPage = document.querySelector('#previousScroller');
const nextPage = document.querySelector('#nextScroller');
const idlePeriod = 100;
const animationDuration = 1000;
let lastAnimation = 0;
let pageIndex = 0;

previousPage.addEventListener('click', ()=> {
    if (pageIndex < 1) return;
    pageIndex--;
    pageList.forEach((section, i) => {
        if (i === pageIndex) {
            section.scrollIntoView({behavior: "smooth"});
        }
    });
});

nextPage.addEventListener('click', () => {
    if (pageIndex > 4) return;
    pageIndex++;
    pageList.forEach((section, i) => {
        if (i === pageIndex) {
            section.scrollIntoView({behavior: "smooth"});
        }
    })
});




document.addEventListener('wheel', event => {
    var delta = event.wheelDelta;
    var timeNow = new Date().getTime();
    // Cancel scroll if currently animating or within quiet period
    if(timeNow - lastAnimation < idlePeriod + animationDuration) {
        event.preventDefault();
        return;
    }

    if (delta < 0) {
        var event = new Event('click');
        nextPage.dispatchEvent(event);
    } else {
        var event = new Event('click');
        previousPage.dispatchEvent(event);
    }

    lastAnimation = timeNow;
},{passive: false});
const pageList=document.querySelectorAll('.verticalPaging');
const previousPage=document.querySelector(“#previousScroller”);
const nextPage=document.querySelector(“#nextScroller”);
常量idlePeriod=100;
常数animationDuration=1000;
设lastAnimation=0;
设pageIndex=0;
上一页。addEventListener('单击',()=>{
if(pageIndex<1)返回;
页面索引--;
页面列表.forEach((节,i)=>{
如果(i==页面索引){
scrollIntoView({行为:“平滑”});
}
});
});
下一页。addEventListener('单击',()=>{
如果(pageIndex>4)返回;
pageIndex++;
页面列表.forEach((节,i)=>{
如果(i==页面索引){
scrollIntoView({行为:“平滑”});
}
})
});
document.addEventListener('wheel',event=>{
var delta=event.wheeldta;
var timeNow=new Date().getTime();
//如果当前正在设置动画或处于静默期,则取消滚动
if(timeNow-lastAnimation
wheel事件没有
wheelDelta
属性,但它有
deltaY
,我猜您实际上在追求它

document.addEventListener('wheel', event => {

    const timeNow = new Date().getTime();

    // Cancel scroll if currently animating or within quiet period
    if(timeNow - lastAnimation < idlePeriod + animationDuration) {
        event.preventDefault();
        return;
    }

    const clickEvent = new Event('click')

    if (event.deltaY < 0) {

        nextPage.dispatchEvent(clickEvent);
    } else {

        previousPage.dispatchEvent(clickEvent);
    }

    lastAnimation = timeNow;
},{passive: false});
document.addEventListener('wheel',event=>{
const timeNow=new Date().getTime();
//如果当前正在设置动画或处于静默期,则取消滚动
if(timeNow-lastAnimation
我冒昧地摆脱了var