Jquery onload/text效果后期反应

Jquery onload/text effect late reaction

本文关键字:onload text Jquery      更新时间:2023-09-26

在我的rails应用程序中有以下代码:

window.onload = ->
  $("#mycontainer").typewriter()
  $("#div1").fadeIn("slow")

作用于此:

  <blockquote class="pull-left">
       <p id="mycontainer">A mathematician, scientist, and engineer are each asked: "Suppose we define a horse's tail to be a leg. How many legs does a horse have?" The mathematician answers "5"; the scientist "1"; and the engineer says "But you can't do that! </p>
       <small id="author">Emmanuel Mensah </small>
  </blockquote>

现在,我可以清楚地看到window.onload函数,我理解它可以让jquery在页面加载后立即启动。我意识到,首先,页面加载,然后在一瞬间,我可以在文本效果出现之前看到(整个)文本(效果是打字,这意味着文本不应该是可见的,而是一个键接一个键地键入……向右)。但我想知道如何做到这一点,这样当页面加载时,我根本看不到文本,而是在jquery启动后。

我尝试将此CSS style: display:none添加到<p>标记中,但这没有任何更改。有人能帮我吗?

首先需要隐藏它们才能看到显示效果。

window.onload = ->
  $("#mycontainer").hide()
  $("#div1").hide()
  $("#mycontainer").typewriter()
  $("#div1").fadeIn("slow")

改为尝试body onload。

<body onload="myfunction()">
  <blockquote class="pull-left">
    <p id="mycontainer" style="display:none;">A mathematician, scientist, and engineer are each asked: "Suppose we define a horse's tail to be a leg. How many legs does a horse have?" The mathematician answers "5"; the scientist "1"; and the engineer says "But you can't do that! </p>
    <small id="author">Emmanuel Mensah </small>
  </blockquote>
</body>
function myfunction() {
  $("#mycontainer").show();
  $("#mycontainer").typewriter();
}