奇怪的间距问题?

huangapple go评论67阅读模式
英文:

Weird spacing issue?

问题

我试图制作一个从屏幕底部开始,一直向上滚动直到一切都离开帧的信用卷轴,而不使用任何库,目前看起来是这样的:

奇怪的间距问题?

有两件事我不喜欢:

  1. 卷轴和名称之间的空间太大了。我没有添加任何换行,不明白为什么会发生这种情况。
  2. 信用卷动画实际上什么都没做。我认为问题出在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:

  1. 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.
  2. 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%;
  }
}

Link: https://jsfiddle.net/3fz568hn/

答案1

得分: 1

  1. 间距是由于CSS的默认h边距引起的。将你的h1h3设置为margin: 0px以删除它,或根据需要进行覆盖。

  2. 动画解决方案,在进行移动动画时,需要使用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%);
  }
}
英文:
  1. The spacing is caused by CSS's default h margin. Set your h1 and h3 to margin: 0px to remove it or overwrite as you need it to.

  2. 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 = [
&quot;You&quot;,
&quot;DevBlizzard&quot;,
&quot;DevBlizzard&quot;,
&quot;DevBlizzard&quot;,
&quot;somebodysomeon2&quot;,
&quot;somebodysomeon2&quot;,
&quot;! kat.#8355&quot;,
&quot;fabianski987&quot;,
&#39;AWSQ - ca8 &lt;a href=&quot;https://playcanvas.com/project/744016/overview/awsq&quot;&gt;(Link)&#39;,
&#39;Uni 05_53 - Craig Kroeger&#39;
];
let titles = [
&quot;Dedicated and Beloved Player:&quot;,
&quot;Mr. CEO:&quot;,
&quot;NOT a war criminal:&quot;,
&quot;Lead Programmer:&quot;,
&quot;Assistant Programmer (not really):&quot;,
&quot;Mr. Break-Your-Game:&quot;,
&quot;Graphic Designer/Artist:&quot;,
&quot;Composer/Sound Effect Designer:&quot;,
&quot;Original Creation:&quot;,
&quot;Font:&quot;
];
let div = document.getElementById(&quot;credits&quot;)
for (let i = 0; i &lt; titles.length; i++) {
let minidiv = document.createElement(&#39;div&#39;);
minidiv.className = &#39;credit&#39;;
let title = document.createElement(&#39;div&#39;);
title.className = &#39;title&#39;;
title.innerHTML = titles[i]; 
minidiv.appendChild(title);
let name = document.createElement(&#39;div&#39;);
name.className = &#39;name&#39;;
name.innerHTML = names[i];
minidiv.appendChild(name);
div.appendChild(minidiv);
}

<!-- language: lang-css -->

body {
background-color: black;
margin: 0;
padding: 0;
}
@import url(&#39;https://fonts.cdnfonts.com/css/public-pixel&#39;);
#credits {
text-align: center;
width: 100%;
height: 100%;
animation: creditRoll 15s linear forwards infinite;
}
#credits .title {
font-family: &#39;Public Pixel&#39;, sans-serif;
color: white;
font-size: 16px;
margin: 5px 0;
}
#credits .name {
font-family: &#39;Public Pixel&#39;, sans-serif;
color: white;
font-size: 16px;
margin-bottom: 20px;
}
@keyframes creditRoll {
0% {
top: translateY(100%);
}
100% {
top: translateY(0%);
}
}

<!-- language: lang-html -->

&lt;link href=&quot;https://fonts.cdnfonts.com/css/public-pixel&quot; rel=&quot;stylesheet&quot;&gt;
&lt;div id=&quot;credits&quot;&gt;
&lt;/div&gt;

<!-- end snippet -->

I don't have the credits.js, so this does not show the animation.

huangapple
  • 本文由 发表于 2023年1月9日 05:10:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/75051315.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定