trigger icon indicating copy to clipboard operation
trigger copied to clipboard

【filter新增平滑参数@有个问题】如果filter和map指定刚好重复的话会返回异常的值

Open RexYao97 opened this issue 2 years ago • 0 comments

这个功能有个问题,如果filter和map指定刚好重复的话会返回异常的值 例子

  <div
        class="lift-transition-sticky-content"
        tg-from="0"
        tg-to="100"
        tg-edge="cover"
        tg-name="position"
        tg-filter="0,50,100@"
        tg-map="0:50;50:0;100:0"
      ></div>

50-100的值为0,但是最终渲染的会是50,因为map也指定了0的映射值 源码问题在这

export function parseValues() {
 
 if (filter.values.length > 0 && !filter.values.includes(value)) {
      if (filter.mode === 'smooth') {
        let region = calcKeyFrameRegion(mapping, value);
       
        if (region.length) {
          // 这里获取的范围值是 0
          value = calcKeyFrameValue(mapping, value, region);
        } else {
          return;
        }
      } else {
        if (filter.mode === 'exact') {
          element.lastValue = null;
          el.style.removeProperty(name);
        }
        return;
      }
    }
  // 这里会根据value的值重新获取映射导致异常
   if (typeof mapping[value] !== 'undefined') {
      value = mapping[value];
    }

}

Originally posted by @RexYao97 in https://github.com/triggerjs/trigger/issues/28#issuecomment-1019912130

RexYao97 avatar Jan 24 '22 09:01 RexYao97