3

我目前有一行文本,其默认字体大小为 24。我将其设置为动画以调整回 22:

$(document).ready(function animateHeader() {
$('#random_header').animate({fontSize : "22px"}, 500);
});

我想在 24 到 22 和 22 到 24 之间连续循环播放这个动画。我该怎么做?

4

3 回答 3

4

jsBin 演示

$(document).ready(function(){
  
  function animateHeader(){
    $('#random_header').animate({fontSize : 22}, 500,function(){
      $(this).animate({fontSize : 24}, 500, animateHeader);
    });
  }
  animateHeader();
  

});
于 2012-05-11T21:32:37.593 回答
3
$(document).ready(function animateHeader() {
    $('#random_header').animate({
        fontSize: $('#random_header').css('fontSize') == '24px' ? '22px' : '24px'
    }, 500, animateHeader);
});​

http://jsfiddle.net/thirtydot/aDZLy/

于 2012-05-11T21:35:07.710 回答
1

尝试

function ani(size){
 $('#random_header').animate({fontSize : size+"px"}, 500, function(){ ani((size==22) ? 24 : 22 ); } );
}

ani(24);
于 2012-05-11T21:34:26.407 回答