简体   繁体   English

如何阻止内容跳跃? (键入js)

[英]How to stop content jumping? (Typed js)

I've written the following code for a static homepage. 我为静态首页编写了以下代码。 In this I want to use the library typed, which is include by the partial "head.html". 在此,我想使用类型化的库,该库包含在部分“ head.html”中。 But because of typed my content keeps jumping. 但是由于打字,我的内容不断跳跃。 This because at a certain point the subtitle container is empty. 这是因为字幕容器在某些时候是空的。 I've tried adding a default placeholder but this doesn't seem to fix the problem. 我尝试添加默认的占位符,但这似乎无法解决问题。

 particlesJS.load('particles-js', '/json/particlesjs-config.json', function() { console.log('callback - particles.js config loaded'); }); var typed = new Typed('#typed', { strings: ['First, solve the problem', 'Some <strong>HTML</strong>', 'Chars &times; &copy;'], typeSpeed: 0, backSpeed: 0, loop: true }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/particlesjs/2.2.2/particles.js"></script> {{ partial "head.html" . }} <section class="hero is-info is-medium"> <div class="hero-head"> {{ partial "navbar.html" .}} </div> <div id="particles-js"></div> <div class="hero-body"> <div class="container has-text-centered"> <p class="title"> </p> <p class="subtitle inline-block" id="typed"> </p> </div> </div> <div class="hero-foot"> <nav class="tabs is-boxed is-fullwidth"> <div class="container"> <ul> <li class="is-active"> <a>Overview</a> </li> <li> <a>Work</a> </li> <li> <a>Grid</a> </li> </ul> </div> </nav> </div> </section> {{ partial "footer.html" .}} 

Could anyone help me out? 有人可以帮我吗?

I ran into a similar problem while trying to use Typed js. 我在尝试使用Typed js时遇到了类似的问题。 After doing some research, I fixed it by adding some css in my code. 经过研究后,我在代码中添加了一些CSS来解决此问题。 This might fix your problem. 这可能会解决您的问题。

In the code you provided, there are two errors. 在您提供的代码中,有两个错误。 Firstly, you need to add a div tag around the p tag with id="typed" and as per the docs , the tag with id="typed" needs to be a span tag. 首先,您需要在带有id="typed"的p标签周围添加一个div标签,并且根据docsid="typed"标签必须是一个span标签。 Secondly, you need to add CSS to increase the height and padding. 其次,您需要添加CSS以增加高度和填充。

Finally, it should Typed js parts should look like this: 最后,它的Typed js部分应如下所示:

<style>
  .text-body {
  height: 100px;
  padding: 10px;
}
</style>

<div class="text-body">
    <span id="typed"></span>
</div>

I recommend to do following trick: to add invisible "cursor char", like this 我建议做以下技巧:添加不可见的“ cursor char”,像这样

  <div class="container"> <div id="typed-strings" style="display:none;">Text here</div> <span id="typed"></span> <span style="visibility:hidden;">|</span> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM