I have a problem when using GSAP's ScrollTrigger.
I set the height of a pinned element in different viewport widths, and it works fine when resizing the window.
But now I want to change hight of the pinned element by clicking the button. I use ScrollTrigger.refresh();
but nothing happens.
Can somebody tell me how to fix it?
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>