【发布时间】:2021-12-19 04:16:53
【问题描述】:
我正在尝试为博客制作此新闻项目组件界面。每个项目显示一个故事图像和文章的一些文本。滚动新闻项目应该“揉搓”图像并显示更多文章的文本。我不明白为什么当您滚动项目时我的动画不保持,然后在执行“解压”之前它完全重置。
有附加和分离到项目的关键帧动画:
@keyframes scrunch {
from {
height: 50%;
}
to {
height: 10%;
}
}
@keyframes unscrunch {
from {
height: 10%;
}
to {
height: 50%;
}
}
.scrunch {
animation: scrunch 1s;
}
.unscrunch {
animation: unscrunch 1s;
}
然后我只是在新闻项目类列表中添加和删除这些类:
const scrunchyBox = document.getElementById('scrunchyBox1');
const children = scrunchyBox.childNodes;
console.dir(children);
const scrunchyBoxHead = children[1];
scrunchyBox.addEventListener('pointerover', (event) => {
scrunchyBoxHead.classList.remove('unscrunch');
scrunchyBoxHead.classList.add('scrunch');
});
scrunchyBox.addEventListener('pointerout', (event) => {
scrunchyBoxHead.classList.remove('scrunch');
scrunchyBoxHead.classList.add('unscrunch');
});
看起来很基本,但无论我在做什么看起来都很恶心。我所做的一切都在my Codepen 结束。
【问题讨论】:
标签: javascript user-interface css-animations