如何使数字淡入,而不是弹出 [英] How to make numbers fade in instead of popping up

查看:166
本文介绍了如何使数字淡入,而不是弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,这有点难以解释这一点,但我试图做在每当一个数字是产生或生成,它淡入,而不是只是弹出。
这里是我试图做的小提琴。我使用输入标记为数字和语句生成其余 -

Okay so this is a bit hard to explain this, but I am trying to make where whenever a number is "spawned" or generated, it fades in instead of just popping up. Here is the Fiddle that I am trying to do that with. I am using a input tag for the number and a for statement to generate the rest--

for (I = 0; I < $("#input:text").val(); I++) {
        N.innerHTML += 1 + I + " "
    }



我希望我解释得很好足够让人理解!

I hope I explained that well enough so people understand!

推荐答案


附加 span

Append span elements instead of text so that you can easily select elements using selector.



p>使用 setTimeout 可以使用 index 连续发生。

Use setTimeout to make it happen serially using index.

尝试此操作:

var D = document,
  In = D.getElementById("input"),
  CC = D.getElementById("submit"),
  N = D.getElementById("N"),
  I;

$(In).keyup(function(Key) {
  if (Key.keyCode == 13) {
    for (var i = 0; i < $("#input:text").val().length; i++) {
      var span = '<span style=\'display:none\'>' + (i + 1) + ' ' + $("#input:text").val()[i] + ' </span>'; //set display of `span` element as `none`
      N.innerHTML += span;
    }
  }
  $('#N span').each(function(i) {
    setTimeout(function() {
      $(this).hide().fadeIn(500);
    }.bind(this), (i * 500)); // `.bind()` will pass the outer `this` context in`setTimeout` when handler is invoked
  })
});

$(CC).click(function() {
  N.innerHTML = "";
});

body {
  cursor: default;
  outline-width: 0px;
}
#main {
  text-align: center;
}

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

<body>
  <div id="main">
    <input type="text" id="input" maxlength="3" placeholder="Press submit to clear all" />
    <input type="submit" id="submit" />
  </div>
  <h1 id="N"></h1>
</body>

小提琴

这篇关于如何使数字淡入,而不是弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆