如何解决将 GSAP Vanilla JS 转换为 GSAP React JS
我想将下面的 Vanilla JS 代码转换为 React JS 代码。我试图用 React Hooks 转换它们,但它不起作用。可以通过提供代码解决方案或参考链接来帮助我学习。
gsap.registerPlugin(ScrollTrigger);
const sections = document.querySelectorAll('.rg__column')
function initHoverReveal() {
sections.forEach(section => {
section.imageBlock = section.querySelector('.rg__image')
section.image = section.querySelector('.rg__image img')
section.mask = section.querySelector('.rg__image--mask')
section.text = section.querySelector('.rg__text')
section.textCopy = section.querySelector('.rg__text--copy')
section.textMask = section.querySelector('.rg__text--mask')
section.textP = section.querySelector('.rg__text--copy p')
gsap.set([section.imageBlock,section.textMask],{yPercent: -101})
gsap.set([section.mask,section.textP],{yPercent: 100})
gsap.set(section.image,{scale: 1.2})
section.addEventListener('mouseenter',createHoverReveal)
section.addEventListener('mouseleave',createHoverReveal)
})
}
function getTextHeight(textCopy) {
return textCopy.clientHeight
}
function createHoverReveal(e) {
// console.log(e.type)
const {imageBlock,mask,text,textCopy,textMask,textP,image} = e.target
let tl = gsap.timeline({
defaults: {
duration: 0.7,ease: 'Power4.out'
}
})
if (e.type === 'mouseenter') {
tl
.to([mask,imageBlock,textP],{yPercent: 0})
.to(text,{y: () => -getTextHeight(textCopy)/2},0)
.to(image,{duration: 1.1,scale: 1},0)
} else if(e.type === 'mouseleave') {
tl
.to([mask,{yPercent: 100})
.to([imageBlock,textMask],{yPercent: -101},0)
.to(text,{y: 0},{scale: 1.2},0)
}
return tl
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。