0
      _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),但我不知道如何。当我调用此函数时,会将元素转换为中心,但希望在函数中添加轻松,如果元素的位置远离中心,则可以轻松进出

4

0 回答 0