【发布时间】:2021-02-10 19:53:09
【问题描述】:
尝试根据窗口宽度修改 gsap scrollTrigger offset_value。不幸的是,当用户“即时”更改窗口大小时,无法弄清楚如何使用(window).resize(function() 实现此目的。此函数对 offset_value 变量没有影响。
这是现在的代码,显然我的方法存在根本性错误:
gsap.registerPlugin(ScrollTrigger);
var frame_count = 37,
offset_value = 360;
if (window.innerWidth < 980) {
offset_value = 180;
}
//This is the part that is not working
jQuery(window).resize(function() {
if( jQuery(this).width() > 979 ){
offset_value=360;}
else {offset_value=180;}
return offset_value;
});
//END This is the part that is not working
gsap.to(".iis-viewer", {
backgroundPosition: (-offset_value * frame_count * 2) + "px 50%",
ease: "steps(" + frame_count + ")", // use a stepped ease for the sprite sheet
scrollTrigger: {
trigger: ".iis-scene",
start: "top top",
end: "+=" + (frame_count * offset_value),
pin: true,
scrub: true
}
});
【问题讨论】:
标签: javascript function variables gsap scrolltrigger