0

在我的 HTML 代码中,我<span>在 a 中有几个标签div,我想使用 GSAP 的插件 ScrollTrigger 为它们设置动画。<div>但是当我使用 span 元素而不是几个标签时,它似乎不起作用。这是代码:

HTML:

<div class="big-box">
  <span id="box">The</span> 
  <span id="box01">rain</span>
  <span id="box02">slacked</span> 
  <span id="box03">still</span> 
  <span id="box04">more.</span> 
  <span id="box05">They</span>
  <span id="box06">crowded</span> 
  <span id="box07">to</span>
  <span id="box08">the</span> 
  <span id="box09">huge</span> 
  <span id="box10">door.</span>
  <span id="box11">The</span> 
  <span id="box12">rain</span> 
  <span id="box13">stopped.</span>
</div>

JS:

gsap.registerPlugin(ScrollTrigger);

let t1 = gsap.timeline();

t1.to("#box",{
  scrollTrigger:{
    trigger: "#box",
    start: "top 80%",
    end: "top 25%",
    scrub: true,
    markers: true
  },
  x: 1000
})
4

1 回答 1

0

ScrollTrigger is working fine with the span as a target. The transform that you're applying doesn't work with spans because of their display of inline. Change the display to inline-block and you'll see it working just fine.

于 2021-01-13T23:58:45.700 回答