我想将gsap与ScrollMagic结合使用。 ScrollMagic已经实现,它工作正常,但当我想使用animation.gsap我得到错误
找不到这些依赖项: * TimelineMax in ./node_modules/scrollmagic/scrollmagic/uncompressed/plugins/animation.gsap.js * ./node_modules/scrollmagic/scrollmagic/uncompressed/plugins/animation.gsap.js中的TweenMax
因此我通过npm
安装了gsapnpm i gsap
并导入了TimelineMax和TweenMax
if (process.browser) {
const sm = require('ScrollMagic')
require('gsap/TimelineMax')
require('gsap/TweenMax')
require('scrollmagic/scrollmagic/uncompressed/plugins/animation.gsap')
require('scrollmagic/scrollmagic/uncompressed/plugins/debug.addIndicators')
Vue.prototype.$sm = sm
Vue.prototype.$smController = new sm.Controller()
}
在我的nuxt.config.js文件中,我将gsap添加到供应商数组
vendor: ['gsap', 'ScrollMagic', 'vuebar', 'vee-validate'],
在我的组件中我使用此代码进行旁白效应
new this.$sm.Scene({
triggerElement: '#js-introduction-paralax',
triggerHook: 'onEnter'
})
.duration('200%')
.setTween('#js-introduction-paralax', {
backgroundPosition: '50% 100%'
ease: Linear.easeNone
})
.addIndicators()
.addTo(this.$smController)
但我仍然得到没有找到家属的错误
更新
我也试图以这种方式导入它
import { TweenMax, TimelineMax, Linear } from 'gsap'
or seperated
import TweenMax from 'gsap/TweenMax';
import TimelineMax from 'gsap/TimelineMax';
但结果相同
我也尝试制作别名
resolve: {
modules:[
path.resolve(__dirname), path.resolve(__dirname, "node_modules")
],
alias: {
"TweenMax": path.resolve('node_modules', 'gsap/TweenMax'),
"TimelineMax": path.resolve('node_modules', 'gsap/TimelineMax'),
"gsap": path.resolve('node_modules', 'gsap'),
}
},
同样的结果
当我在控制台中写字时
window.TweenMax
我明白了
ƒ (target, duration, vars) {
TweenLite.call(this, target, duration, vars);
this._cycle = 0;
this._yoyo = (this.vars.yoyo === true || !!this.vars.yoyoEase);
this._repeat = this.vars.repe…
所以有些东西被加载......
答案 0 :(得分:0)
这可能对您有用。 我也有像您这样的错误,并且找到了解决问题here的方法。
import ScrollMagic from 'scrollmagic'
import {
TweenMax,
TimelineLite
} from 'gsap'
import 'imports-loader?define=>false!scrollmagic/scrollmagic/uncompressed/plugins/debug.addIndicators'
import 'imports-loader?define=>false!scrollmagic/scrollmagic/uncompressed/plugins/animation.gsap'
别忘了做
npm i scrollmagic imports-loader