日期:2014-05-16  浏览次数:20330 次

jQuery1.4 中逐个修改一句话中各个字的字体大小
如何逐个修改一句话中的字体大小?
比如说,hello world,先将h变大,然后在变小,然后e也是这样,以此类推。

<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("input").click(function(){
  $("span").animate({fontSize:"50px"},1000,function(){
    $(this).animate({fontSize:"20px"},10000);
    });
  });
});
</script>
</head>
<body>
<input type="button" value="Start"><br/>
<span>H</span> <span>e</span> <span>l</span> <span>l</span> <span>o</span> <span>,</span> <span>W</span> <span>o</span> <span>r</span> <span>l</span> <span>d</span> <span>!</span>
</body>

</html>


------解决方案--------------------

<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0-rc1.js"></script>
<script type="text/javascript">
var i = 0;
var st;
$(document).ready(function(){
  $("input").click(function(){
    st = setInterval(sleep,2000);
    
  })
  
});
function sleep(numberMillis) {
    var span = $("span");
    var len = $("span").length;

    for(;i<len;){
      $(span[i]).animate({fontSize:"50px"},1000,function(){
    $(this).animate({fontSize:"20px"},10000);
    });
      i++ 
      break;
    }
    if(i == len){
      clearInterval(st);
    }
}
</script>
</head>
<body>
<input type="button" value="Start"><br/>
<span>H</span> <span>e</span> <span>l</span> <span>l</span> <span>o</span> <span>,</span> <span>W</span> <span>o</span> <span>r</span> <span>l</span> <span>d</span> <span>!</span>
</body>

</html>


可以实现你要的功能但是效果不是很好 自己在优化下
------解决方案--------------------

<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0-rc1.js"></script>
<style>
div{line-height:60px;text-align:center}
</style>
<script type="text/javascript">
$(document).ready(function(){
var span=$("span"),arr=[60, 55, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5,5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 55, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5,5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60],l=0,k;