我在我的wheel类中有一个到center方法的转换,并尝试向其添加easeinout函数,以便在距离中心较远时更快

zy1mlcev  于 2021-09-13  发布在  Java
关注(0)|答案(0)|浏览(151)
_transformToCenter(id) {
        const increment = 1;
        const myTarget = document.getElementById(id);
        const { x, width } = myTarget.getBoundingClientRect();
        const elementCenter = x + ((width / 2));
        const diff = this.center - elementCenter;

        if (diff < 0) {
          this.container.scrollLeft += increment;
        } else {
          this.container.scrollLeft -= increment;
        }
        this._resizeAll();
        if (diff < -SWIPE_THRESHOLD || diff > SWIPE_THRESHOLD) {
          setTimeout(() => {
            this._transformToCenter(id);
          }, TRANSFORM_TIME);
        }
      }

      _easeInOutQuad(x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t + b;
        return -c / 2 * ((--t) * (t - 2) - 1) + b;
      }

需要添加这样的函数(easeinoutquad),但我不知道如何添加。当我调用此函数时,它会将元素转换为中心,但希望添加ease-in函数,即如果元素的位置远离中心,则可以进行ease-in和ease-out

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题