英文:
Weird spacing issue?
问题
我试图制作一个从屏幕底部开始,一直向上滚动直到一切都离开帧的信用卷轴,而不使用任何库,目前看起来是这样的:
有两件事我不喜欢:
- 卷轴和名称之间的空间太大了。我没有添加任何换行,不明白为什么会发生这种情况。
- 信用卷动画实际上什么都没做。我认为问题出在CSS中,但我不太确定。
有什么帮助吗?
body {
background-color: black;
margin: 0;
padding: 0;
}
@font-face {
font-family: Pixelated;
src: url(uni05_53.ttf);
}
h1 {
font-family: Pixelated;
color: white;
}
h3 {
font-family: Pixelated;
color: white;
font-size: 25px;
}
.credits {
text-align: center;
width: 100%;
height: 100%;
}
.credit {
animation: creditRoll 15s linear forwards infinite;
}
@keyframes creditRoll {
0% {
top: 100%;
}
100% {
top: -100%;
}
}
链接: https://jsfiddle.net/3fz568hn/
英文:
So I'm trying to make a credit roll that starts from the bottom of the screen, moving all the way up until everything is out of frame without using any libraries, and right now, this is what it's looking like:
And there are two things that I dislike:
- The space in between the role and the name is way too big. I haven't added any breaks for this to be happening, and I don't understand why that is.
- The credit roll animation doesn't actually do anything at all. I think the issue lies within the CSS, but I'm not too sure.
Any help please?
body {
background-color: black;
margin: 0;
padding: 0;
}
@font-face {
font-family: Pixelated;
src: url(uni05_53.ttf);
}
h1 {
font-family: Pixelated;
color: white;
}
h3 {
font-family: Pixelated;
color: white;
font-size: 25px;
}
.credits {
text-align: center;
width: 100%;
height: 100%;
}
.credit {
animation: creditRoll 15s linear forwards infinite;
}
@keyframes creditRoll {
0% {
top: 100%;
}
100% {
top: -100%;
}
}
答案1
得分: 1
-
间距是由于CSS的默认
h
边距引起的。将你的h1
和h3
设置为margin: 0px
以删除它,或根据需要进行覆盖。 -
动画解决方案,在进行移动动画时,需要使用
transform
属性指定位置,而不是常规的top、left等。
.credits {
text-align: center;
width: 100%;
height: 100%;
overflow: hidden;
animation: creditRoll 5s linear forwards;
}
@keyframes creditRoll {
0% {
transform: translateY(100%);
}
50% {
transform: translateY(0%);
}
100% {
transform: translateY(-100%);
}
}
英文:
-
The spacing is caused by CSS's default
h
margin. Set yourh1
andh3
tomargin: 0px
to remove it or overwrite as you need it to. -
Solution for animation, when doing those move animation, you need to specifiy positions with
transform
property rather than normal top, left, etc
.credits {
text-align: center;
width: 100%;
height: 100%;
overflow: hidden;
animation: creditRoll 5s linear forwards;
}
@keyframes creditRoll {
0% {
transform: translateY(100%);
}
50% {
transform:translatey(0%);
}
100% {
transform:translatey(-100%);
}
}
答案2
得分: 0
您不需要使用标题,最好使用带有间距的 `div` 标签:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
let names = [
"You",
"DevBlizzard",
"DevBlizzard",
"DevBlizzard",
"somebodysomeon2",
"somebodysomeon2",
"! kat.#8355",
"fabianski987",
'AWSQ - ca8 <a href="https://playcanvas.com/project/744016/overview/awsq">(Link)</a>',
'Uni 05_53 - Craig Kroeger'
];
let titles = [
"专注且受人喜爱的玩家:",
"首席执行官:",
"并非战争罪犯:",
"首席程序员:",
"助理程序员(实际上不是):",
"破坏你游戏的先生:",
"图形设计师/艺术家:",
"作曲家/音效设计师:",
"原创:",
"字体:"
];
let div = document.getElementById("credits")
for (let i = 0; i < titles.length; i++) {
let minidiv = document.createElement('div');
minidiv.className = 'credit';
let title = document.createElement('div');
title.className = 'title';
title.innerHTML = titles[i];
minidiv.appendChild(title);
let name = document.createElement('div');
name.className = 'name';
name.innerHTML = names[i];
minidiv.appendChild(name);
div.appendChild(minidiv);
}
<!-- language: lang-css -->
body {
background-color: black;
margin: 0;
padding: 0;
}
@import url('https://fonts.cdnfonts.com/css/public-pixel');
#credits {
text-align: center;
width: 100%;
height: 100%;
animation: creditRoll 15s linear forwards infinite;
}
#credits .title {
font-family: 'Public Pixel', sans-serif;
color: white;
font-size: 16px;
margin: 5px 0;
}
#credits .name {
font-family: 'Public Pixel', sans-serif;
color: white;
font-size: 16px;
margin-bottom: 20px;
}
@keyframes creditRoll {
0% {
top: translateY(100%);
}
100% {
top: translateY(0%);
}
}
<!-- language: lang-html -->
<link href="https://fonts.cdnfonts.com/css/public-pixel" rel="stylesheet">
<div id="credits">
</div>
<!-- end snippet -->
我没有 `credits.js`,所以这不会显示动画。
英文:
You don't need to use headings, better to specify div
tags with margin:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
let names = [
"You",
"DevBlizzard",
"DevBlizzard",
"DevBlizzard",
"somebodysomeon2",
"somebodysomeon2",
"! kat.#8355",
"fabianski987",
'AWSQ - ca8 <a href="https://playcanvas.com/project/744016/overview/awsq">(Link)',
'Uni 05_53 - Craig Kroeger'
];
let titles = [
"Dedicated and Beloved Player:",
"Mr. CEO:",
"NOT a war criminal:",
"Lead Programmer:",
"Assistant Programmer (not really):",
"Mr. Break-Your-Game:",
"Graphic Designer/Artist:",
"Composer/Sound Effect Designer:",
"Original Creation:",
"Font:"
];
let div = document.getElementById("credits")
for (let i = 0; i < titles.length; i++) {
let minidiv = document.createElement('div');
minidiv.className = 'credit';
let title = document.createElement('div');
title.className = 'title';
title.innerHTML = titles[i];
minidiv.appendChild(title);
let name = document.createElement('div');
name.className = 'name';
name.innerHTML = names[i];
minidiv.appendChild(name);
div.appendChild(minidiv);
}
<!-- language: lang-css -->
body {
background-color: black;
margin: 0;
padding: 0;
}
@import url('https://fonts.cdnfonts.com/css/public-pixel');
#credits {
text-align: center;
width: 100%;
height: 100%;
animation: creditRoll 15s linear forwards infinite;
}
#credits .title {
font-family: 'Public Pixel', sans-serif;
color: white;
font-size: 16px;
margin: 5px 0;
}
#credits .name {
font-family: 'Public Pixel', sans-serif;
color: white;
font-size: 16px;
margin-bottom: 20px;
}
@keyframes creditRoll {
0% {
top: translateY(100%);
}
100% {
top: translateY(0%);
}
}
<!-- language: lang-html -->
<link href="https://fonts.cdnfonts.com/css/public-pixel" rel="stylesheet">
<div id="credits">
</div>
<!-- end snippet -->
I don't have the credits.js
, so this does not show the animation.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论