要将ScrollMagic与GSAP一起使用,您需要加载animation.gsap.js插件.使用Webpack,您可以执行以下操作(假设您使用CommonJS语法并使用npm安装所有内容):
var TweenMax = require('gsap');
var ScrollMagic = require('scrollmagic');
require('ScrollMagicGSAP');
Run Code Online (Sandbox Code Playgroud)
要确保这实际上有效,您必须为Webpack配置添加别名,以便Webpack知道插件的位置.
resolve: {
alias: {
'ScrollMagicGSAP': 'scrollmagic/scrollmagic/uncompressed/plugins/animation.gsap'
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,当您使用此配置和上面的CommonJS语法时,ScrollMagic会继续抛出错误.
(ScrollMagic.Scene) -> ERROR calling setTween() due to missing Plugin 'animation.gsap'. Please make sure to include plugins/animation.gsap.js
Run Code Online (Sandbox Code Playgroud)