已关闭。此问题需要details or clarity。它目前不接受回答。
**希望改进此问题?**通过editing this post添加详细信息并阐明问题。
4天前关闭。
此帖子是在3天前编辑并提交审查的。
Improve this question的
我对HTML和CSS非常陌生。我的HTML
中有一个块引号,其中包含不同span类中的单词,如下所示:
<div class="quote" id="quote">
<blockquote>
<p>
<span class="left-quote">“</span>
<span>This</span>
<span>is</span>
<span>my</span>
<span>quote</span>
<span class="right-quote">”</span>
</p>
</blockquote>
</div>
字符串
然后,我在CSS中对引用应用了动画,以便文本慢慢淡入。下面是我的CSS:
* {
padding: 0;
margin: 0;
}
body {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.quote p {
font-family: "Montserrat Medium";
max-width: 40ch;
text-align: center;
transform: scale(0.94);
animation: scale 3s forwards cubic-bezier(0.5, 1, 0.89, 1);
}
@keyframes scale {
100% {
transform: scale(1);
}
}
span {
display: inline-block;
opacity: 0;
filter: blur(4px);
}
span:nth-child(1) {
animation: fade-in 0.8s 0.1s forwards cubic-bezier(0.11, 0, 0.5, 0);
}
span:nth-child(2) {
animation: fade-in 0.8s 0.2s forwards cubic-bezier(0.11, 0, 0.5, 0);
}
span:nth-child(3) {
animation: fade-in 0.8s 0.3s forwards cubic-bezier(0.11, 0, 0.5, 0);
}
span:nth-child(4) {
animation: fade-in 0.8s 0.4s forwards cubic-bezier(0.11, 0, 0.5, 0);
}
span:nth-child(5) {
animation: fade-in 0.8s 0.5s forwards cubic-bezier(0.11, 0, 0.5, 0);
}
span:nth-child(6) {
animation: fade-in 0.8s 0.6s forwards cubic-bezier(0.11, 0, 0.5, 0);
}
@keyframes fade-in {
100% {
opacity: 1;
filter: blur(0);
}
}
型
我现在要做的是,当用户滚动到页面中div
处于活动状态的部分时,生成这个动画。
我使用以下方法来实现这一点:
const element = document.getElementById('quote');
const observer = new IntersectionObserver(entries => {
element.classList.toggle('quote', entries[0].isIntersecting );
});
observer.observe(element)
型
然而,这只会触发报价上的动画,我相信是这一部分:
.quote p {
font-family: "Montserrat Medium";
max-width: 40ch;
text-align: center;
transform: scale(0.94);
animation: scale 3s forwards cubic-bezier(0.5, 1, 0.89, 1);
}
型
我怎样才能让动画在跨度和每个单词上工作?
我试过使用这些,但都没有成功:
const element = document.getElementById('quote');
const observer = new IntersectionObserver(entries => {
element.classList.toggle('quote span', entries[0].isIntersecting );
});
observer.observe(element)
型
还有这个
const element = document.getElementById('quote');
const observer = new IntersectionObserver(entries => {
element.classList.toggle('quote', 'span', entries[0].isIntersecting );
});
observer.observe(element)
型
* {
padding: 0;
margin: 0;
}
body {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.quote p {
font-family: "Montserrat Medium";
max-width: 40ch;
text-align: center;
transform: scale(0.94);
animation: scale 3s forwards cubic-bezier(0.5, 1, 0.89, 1);
}
@keyframes scale {
100% {
transform: scale(1);
}
}
span {
display: inline-block;
opacity: 0;
filter: blur(4px);
}
span:nth-child(1) {
animation: fade-in 0.8s 0.1s forwards cubic-bezier(0.11, 0, 0.5, 0);
}
span:nth-child(2) {
animation: fade-in 0.8s 0.2s forwards cubic-bezier(0.11, 0, 0.5, 0);
}
span:nth-child(3) {
animation: fade-in 0.8s 0.3s forwards cubic-bezier(0.11, 0, 0.5, 0);
}
span:nth-child(4) {
animation: fade-in 0.8s 0.4s forwards cubic-bezier(0.11, 0, 0.5, 0);
}
span:nth-child(5) {
animation: fade-in 0.8s 0.5s forwards cubic-bezier(0.11, 0, 0.5, 0);
}
span:nth-child(6) {
animation: fade-in 0.8s 0.6s forwards cubic-bezier(0.11, 0, 0.5, 0);
}
@keyframes fade-in {
100% {
opacity: 1;
filter: blur(0);
}
}
<!DOCTYPE html>
<html lang="en">
<!-- Head -->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Cedarville+Cursive&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="blur.css">
</head>
<!-- Body -->
<body>
<div class="quote" id="quote">
<blockquote>
<p>
<span class="left-quote">“</span>
<span>This</span>
<span>is</span>
<span>my</span>
<span>quote</span>
<span class="right-quote">”</span>
</p>
</blockquote>
</div>
</body>
</html>
1条答案
按热度按时间2exbekwf1#
因为我不知道你的HTML看起来怎么样。我必须对输出的外观进行有根据的猜测。
如果你有多个引用块,它会查找
.quote
并迭代这些引用块,然后将相同的引用块应用到页面上的每个.quote
。你必须修改它以适合你的
HTML
,但我希望这个JS
能在路上对你有所帮助。祝你今天愉快!