为了逼真,给填色的span设置背景色,其宽度就是进度的百分比,最后就用js来模拟进度的变化了:
// 模拟进度 function progressBar() { var max = 100; var init = 0; var uploaded; var test = setInterval(function() { init += 10; uploaded = parseInt((init / max * 100)) + '%'; $uploadTextSpan.text(uploaded).next().css({ width:uploaded }); if (init === 100) { clearInterval(test); $uploadTextSpan.text('上传完成'); $('.confirm-cancel span').css({ cursor:'pointer' }); $('.confirm').css({ backgroundColor:'rgb(111,197,293)' }); $('.cancel').css({ backgroundColor:'rgb(175,194,211)' }) $closeConfirmCancel.on('click',closeConfirmCancel); } else { $closeConfirmCancel.off('click',closeConfirmCancel); $('.upload-close-span').on('click',function(){ clearInterval(test); closeConfirmCancel(); }); $uploadMask.on('click',function() { clearInterval(test); closeConfirmCancel(); }) } },1000); }