添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
    gsap.utils.toArray('.slide-up').forEach((elem: any) => {
      gsap.fromTo(
        elem,
        // elem! as gsap.DOMTarget,
          y: 100,
          opacity: 0,
          scrollTrigger: {
            trigger: elem,
            start: '-80px bottom',
          duration: 2,
          ease: 'expo.out',
          y: 0,
          opacity: 1,
	All is fine except for the types I had to assign, namely I can only run this when the 'elem' has type 'any'. I tried assigning other, more fitting types such as 'HTMLDivElement', but then TS complains that 
Argument of type '(elem: HTMLDivElement) => void' is not assignable to parameter of type '(value: unknown, index: number, array: unknown[]) => void'.
Types of parameters 'elem' and 'value' are incompatible.
Type 'unknown' is not assignable to type 'HTMLDivElement'.ts(2345)
If I try casting it as unknown, then the scrollTrigger throws a fuss about it:
Type 'unknown' is not assignable to type 'DOMTarget | undefined'.
  Type 'unknown' is not assignable to type 'ArrayLike<string | Element | null>'.ts(2322)