Javascript 在animate()之后使用jQuery text()时无法正常工作
我正在尝试制作一个动画进度条,目前为止我有以下代码: HTML 问题是text()仅在所有动画完成后才会更改,因此,您无法看到(1%)、(2%、(3%)等,您只能在三个动画完成时看到(3%)Javascript 在animate()之后使用jQuery text()时无法正常工作,javascript,jquery,Javascript,Jquery,我正在尝试制作一个动画进度条,目前为止我有以下代码: HTML 问题是text()仅在所有动画完成后才会更改,因此,您无法看到(1%)、(2%、(3%)等,您只能在三个动画完成时看到(3%) 提前感谢实际上,它会在动画开始之前更改文本,如果您希望在动画之后发生某些事情,请使用动画回调 $(document).ready(function(){ $('button').click(function(){ $('.loader').fadeIn(1200);
提前感谢实际上,它会在动画开始之前更改文本,如果您希望在动画之后发生某些事情,请使用动画回调
$(document).ready(function(){
$('button').click(function(){
$('.loader').fadeIn(1200);
$('.bar-value').animate({width: '+=1%'},100, function(){
$('.progress').text("1%");
});
$('.bar-value').animate({width: '+=1%'},100, function(){
$('.progress').text("2%");
});
$('.bar-value').animate({width: '+=1%'},100, function(){
$('.progress').text("3%");
});
});
});
实际上,它在动画开始之前更改文本,如果您希望在动画之后发生某些事情,请使用动画回调
$(document).ready(function(){
$('button').click(function(){
$('.loader').fadeIn(1200);
$('.bar-value').animate({width: '+=1%'},100, function(){
$('.progress').text("1%");
});
$('.bar-value').animate({width: '+=1%'},100, function(){
$('.progress').text("2%");
});
$('.bar-value').animate({width: '+=1%'},100, function(){
$('.progress').text("3%");
});
});
});
实际上,它在动画开始之前更改文本,如果您希望在动画之后发生某些事情,请使用动画回调
$(document).ready(function(){
$('button').click(function(){
$('.loader').fadeIn(1200);
$('.bar-value').animate({width: '+=1%'},100, function(){
$('.progress').text("1%");
});
$('.bar-value').animate({width: '+=1%'},100, function(){
$('.progress').text("2%");
});
$('.bar-value').animate({width: '+=1%'},100, function(){
$('.progress').text("3%");
});
});
});
实际上,它在动画开始之前更改文本,如果您希望在动画之后发生某些事情,请使用动画回调
$(document).ready(function(){
$('button').click(function(){
$('.loader').fadeIn(1200);
$('.bar-value').animate({width: '+=1%'},100, function(){
$('.progress').text("1%");
});
$('.bar-value').animate({width: '+=1%'},100, function(){
$('.progress').text("2%");
});
$('.bar-value').animate({width: '+=1%'},100, function(){
$('.progress').text("3%");
});
});
});
animate在动画完成时接受回调animate在动画完成时接受回调animate在动画完成时接受回调animate在动画完成时接受回调