gpt4 book ai didi

javascript - Css 文本动画问题

转载 作者:行者123 更新时间:2023-11-28 17:04:11 25 4
gpt4 key购买 nike

下面的代码应该在向下滚动时显示“Dedicated People”,出于某种原因它在我的浏览器中不起作用?我忘记了一个引用吗?当我使用 codepen 时它工作正常但在任何其他浏览器中它不显示任何内容。这背后的原因是什么,我该如何为 chrome 浏览器解决这个问题。

$(function() {
var text = $(".text");
$(window).scroll(function() {
var scroll = $(window).scrollTop();

if (scroll >= 10) {
text.removeClass("hidden");
} else {
text.addClass("hidden");
}
});
});
@import url('https://fonts.googleapis.com/css?family=Muli:300,400,700');

* {
margin: 0;
padding: 0;
}
body {
background-color: #000;
height: 200vh;
font-family: 'Muli', sans-serif;
}
.text {
position: fixed;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
list-style: none;
border-bottom: 0;
}

.text.hidden {
border-bottom: 1px solid #fff;
}

.text li {
display: inline-block;
float: left;
font-weight: 700;
font-size: 2em;
color: #fff;
opacity: 1;
transition: all 0.5s ease-in-out;
max-width: 2em;
}
.text.hidden li.spaced {
padding-left: 0;
}
.text li.spaced {
padding-left: 0.5em;
}

.text.hidden li.ghost {
opacity: 0;
max-width: 0;
}
<ul class="text hidden">
<li>D</li>
<li class="ghost">e</li>
<li class="ghost">d</li>
<li class="ghost">i</li>
<li class="ghost">c</li>
<li class="ghost">a</li>
<li class="ghost">t</li>
<li class="ghost">e</li>
<li class="ghost">d</li>
<li class="spaced">P</li>
<li class="ghost">e</li>
<li class="ghost">o</li>
<li class="ghost">p</li>
<li class="ghost">l</li>
<li class="ghost">e</li>
</ul>

最佳答案

看起来你忘记了 Jquery 脚本:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

这是 JSFiddle: https://jsfiddle.net/8dc7toLn/

$(function() {
var text = $(".text");
$(window).scroll(function() {
var scroll = $(window).scrollTop();

if (scroll >= 10) {
text.removeClass("hidden");
} else {
text.addClass("hidden");
}
});
});
@import url('https://fonts.googleapis.com/css?family=Muli:300,400,700');

* {
margin: 0;
padding: 0;
}
body {
background-color: #000;
height: 200vh;
font-family: 'Muli', sans-serif;
}
.text {
position: fixed;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
list-style: none;
border-bottom: 0;
}

.text.hidden {
border-bottom: 1px solid #fff;
}

.text li {
display: inline-block;
float: left;
font-weight: 700;
font-size: 2em;
color: #fff;
opacity: 1;
transition: all 0.5s ease-in-out;
max-width: 2em;
}
.text.hidden li.spaced {
padding-left: 0;
}
.text li.spaced {
padding-left: 0.5em;
}

.text.hidden li.ghost {
opacity: 0;
max-width: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul class="text hidden">
<li>D</li>
<li class="ghost">e</li>
<li class="ghost">d</li>
<li class="ghost">i</li>
<li class="ghost">c</li>
<li class="ghost">a</li>
<li class="ghost">t</li>
<li class="ghost">e</li>
<li class="ghost">d</li>
<li class="spaced">P</li>
<li class="ghost">e</li>
<li class="ghost">o</li>
<li class="ghost">p</li>
<li class="ghost">l</li>
<li class="ghost">e</li>
</ul>

关于javascript - Css 文本动画问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50694623/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com