欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于jQuery實(shí)現(xiàn)文字打印動(dòng)態(tài)效果

 更新時(shí)間:2017年04月21日 08:52:20   作者:mmklzmant  
這篇文章主要介紹了基于jQuery實(shí)現(xiàn)文字打印動(dòng)態(tài)效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了jQuery實(shí)現(xiàn)文字打印動(dòng)態(tài)效果的具體代碼,供大家參考,具體內(nèi)容如下

主體html

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>打印文字效果</title>
  <script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
  <script type="text/javascript">

  <script/>
<head>
<body>
  <p id="typing">The furthest distance in the world.Is not between life and death.But when I stand in front of you.Yet you don't know that I love you</p>
</body>

對(duì)于JQuery的引用,可以先到JQuery官網(wǎng)下載相應(yīng)的版本,引用的時(shí)候加入相應(yīng)的目錄就可以了

接下來就是在script標(biāo)簽中添加代碼實(shí)現(xiàn)文字的動(dòng)態(tài)效果了,先上代碼

<script>
  $(dcument).ready(function(){
    typing();
  })
  var text;//p標(biāo)簽里對(duì)應(yīng)的字符串
  var index = 0;//text字符串的下標(biāo)
  var id;//setTimeout()的返回值,用于關(guān)閉clearTimeout(id)
  function typing()
  {
    text = $("#typing").text();
    $("#typing").text("");
    $("#typing").show();
    typed();
  }
  result = "";
  function typed(){
    result += text.charAt(index);
    $("#typing").text(result + (index & 1 ? "_" : " "));
    if(index < text.length - 1)
    {
      index++;
      id = setTimeout("typed()", 100);
    }
    else
      clearTimeout(id);
  }
</script>

為什么顯示文字的時(shí)候是result+ (index & 1 ? "_" : " ")呢,當(dāng)然是為了打印的動(dòng)態(tài)效果了,當(dāng)下標(biāo)index為奇數(shù)的時(shí)候最后一個(gè)字符顯示為"_",當(dāng)為偶數(shù)的時(shí)候顯示" ",這樣就能形成打印文字的那種動(dòng)態(tài)效果。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論