4

GSAP の ScrollTrigger を使用する際に問題が発生します。

ピン留めされた要素の高さをさまざまなビューポート幅に設定すると、ウィンドウのサイズを変更するときにうまく機能します。

しかし今、ボタンをクリックしてピン留めされた要素の高さを変更したいと考えています。使用していますScrollTrigger.refresh();が、何も起こりません。

誰かがそれを修正する方法を教えてもらえますか?

ScrollTrigger.create({
  trigger: '.box',
  pin: true,
  start: 'top center',
  end: () => `+=${$('.h-500').height() - $('.box').height()}`,
  markers: true,
  id: "box",
  onRefreshInit: () => {
  },
  onRefresh: () => {
  }
});

function resizeBox(){
  $('.box').css('height', '50px');
  ScrollTrigger.refresh();
}
body{
  margin: 0;
}
.space {
  width: 100%;
}
.h-500 {
  height: 500px;
  background: yellow;
}
.h-1000 {
  height: 1000px;
}
.box {
  width: 100px;
  height: 100px;
  background: red;
}
button {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 999;
  font-size: 20px;
}

@media only screen and (max-width: 600px) {
  .box {
    height: 5vw;
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://unpkg.com/gsap@3/dist/ScrollTrigger.min.js"></script>
<script src="https://unpkg.co/gsap@3/dist/gsap.min.js"></script>

<div class="space h-1000"></div>

<div class="space h-500">
  <div class="box"></div>
</div>

<div class="space h-1000"></div>

<button onclick="resizeBox()">resizeBox</button>

4

1 に答える 1