试图根据窗口宽度修改 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
}
});