javascript文字逐字输出精简案例

2016-10-17 10:44:09

javascript逐字输出案例

  1. //动态文字提示 
  2.             var txtArr = ['欢迎来到爱思资源网,官网地址:http://www.aseoe.com/''专注Web前端开发与PHP编程设计'], 
  3.                 x = 1, 
  4.                 y = 0, 
  5.                 txt = txtArr[y], 
  6.                 timer = null
  7.                 timer1 = null
  8.                 cue = $('.menutext');  
  9.             function changTxt() { 
  10.                 if (x == txt.length+1) { 
  11.                     clearTimeout(timer1); 
  12.                     timer1 = setInterval(function(){ 
  13.                         y += 1; 
  14.                         if (y > txtArr.length - 1) y = 0; 
  15.                         cue.text(''); 
  16.                         txt = txtArr[y]; 
  17.                         x=0; 
  18.                     },5500);                     
  19.                 } 
  20.                 cue.text(txt.substring(0,x)); 
  21.                 x+=1; 
  22.                 clearTimeout(timer); 
  23.                 timer = setTimeout(function(){ 
  24.                     changTxt(); 
  25.                 },600); 
  26.             } 
  27.             changTxt(); 

 点击查看案例

为您推荐