我有多个触发器,每个触发器执行以下操作:
1.显示/删除画布
1.更改节的背景色
1.在视图中播放/暂停视频
1.播放/暂停CSS动画
前两个工作时,没有其他2个触发器,我得到这个错误的播放暂停视频:未捕获的类型错误:无法读取null的属性(读取'play')但是,我已经遵循了GSAP教程,所以我只能假设与前面的触发器有冲突。
const hideWebGl = gsap.timeline({
scrollTrigger: {
trigger: ".wriggle-cursor",
scrub: true,
start: 'top 100%',
end: 'top -125%',
onEnter: () => $('.home #canvas').css('display','block'),
onLeave: () => $('.home #canvas').css('display','none'),
onEnterBack: () => $('.home #canvas').css('display','block'),
onLeaveBack: () => $('.home #canvas').css('display','none'),
},
});
const projectsBackground = gsap.timeline({
scrollTrigger: {
trigger: ".projects-section-next .whatwedo",
scrub: true,
start: 'top 60%',
end: 'top -300%',
onEnter: () => $('.projects-section-next .whatwedo').css('background-color','white'),
onLeave: () => $('.projects-section-next .whatwedo').css('background-color','transparent'),
onEnterBack: () => $('.projects-section-next .whatwedo').css('background-color','white'),
onLeaveBack: () => $('.projects-section-next .whatwedo').css('background-color','transparent'),
},
});
let allVideoDivs = gsap.utils.toArray('.vid-gsap');
allVideoDivs.forEach((videoDiv, i) => {
let videoElem = videoDiv.querySelector('video')
ScrollTrigger.create({
trigger: videoElem,
start: 'top 80%',
end: 'top 20%',
markers: true,
onEnter: () => videoElem.play(),
onEnterBack: () => videoElem.play(),
onLeave: () => videoElem.pause(),
onLeaveBack: () => videoElem.pause(),
});
});
let allCssAnimation = gsap.utils.toArray('.ticker-marquee');
allCssAnimation.forEach((cssAnimation, i) => {
let cssElem = cssAnimation.querySelector('video')
ScrollTrigger.create({
trigger:cssElem,
start: 'top 80%',
end: 'top 20%',
markers: true,
onEnter: () => cssElem.css('-webkit-animation-play-state','running'),
onLeave: () => cssElem.css('-webkit-animation-play-state','paused'),
onEnterBack: () => cssElem.css('-webkit-animation-play-state','running'),
onLeaveBack: () => cssElem.css('-webkit-animation-play-state','paused'),
});
});
1条答案
按热度按时间jjhzyzn01#
我把视频播放暂停部分改成了这个,它修好了。