Javascript 视差自定义功能滚动效果问题

Javascript 视差自定义功能滚动效果问题,javascript,html,css,parallax,Javascript,Html,Css,Parallax,示例 我对上下滚动效果的代码有问题。关键问题是: //create the event listener of the users choice. window.addEventListener(this.trigger,function(){ //get the current position of scroll and add it to the object self.scrollPos= this.scrollY || this.page

示例

我对上下滚动效果的代码有问题。关键问题是:

    //create the event listener of the users choice.
    window.addEventListener(this.trigger,function(){
        //get the current position of scroll and add it to the object
        self.scrollPos= this.scrollY || this.pageYoffset;

        //get the current position of the element
        newPos = getPosition(self.target,self.dir);

//HERE IS THE BIG ISSUE!!!!!!!
        //adjust the current position depending on the scroll direction
        if(scrollex.direction == "down"){
        self.target.style[self.dir]= newPos + (self.scrollPos * self.offset)+"px";
        }else{
        self.target.style[self.dir]= newPos - (this.scrollY * self.offset)+"px";
        }

        //run callback if there is one
        if(callback !== null && typeof callback=='function'){
            callback.call(self);
        }
    }, false);
我没有让正确的PXs回到正确的位置。我添加了小提琴,因为它有所有主要的代码和注释。以及我为帮助实现这个
scrollex
功能而添加的额外功能

有谁能建议一个更好的数学方程式来来回得到正确的pxs吗。尝试一下,玩一下,让我知道任何好的建议。我已经深入了解了这一点,还有更多的内容要补充,但到目前为止,向下和向上滚动部分系统主要是有缺陷的。你们可以看到,一旦你们开始前后滚动,它确实会前后移动,但向上移动所产生的像素比向下移动所产生的像素要少