js怎么实现这种进度条,随着液体到达数字之后,数字就会自下而上的变白?

JavaScript012

js怎么实现这种进度条,随着液体到达数字之后,数字就会自下而上的变白?,第1张

我想到三种实现方法:

1、CSS字体支持反色效果。你可以用css实现。

2、CSS得遮罩效果,做两层把下面遮住,一点点露出来。

3、用canvas绘图。

ajax的表单提交只能提交data数据到后台,没法实现file文件的上传还有展示进度功能,这里用到form.js的插件来实现,搭配css样式简单易上手,而且高大上,推荐使用。

需要解释下我的结构, #upload-input-file 的input标签是真实的文件上传按钮,包裹form标签后可以实现上传功能, #upload-input-btn 的button标签是展示给用户的按钮,因为需要样式的美化。上传完成生成的文件名将会显示在 .upload-file-result 里面, .progress 是进度条的位置,先让他隐藏加上 hidden 的class, .progress-bar 是进度条的主体, .progress-bar-status 是进度条的文本提醒。

去掉hidden的class,看到的效果是这样的

[图片上传失败...(image-2c700a-1548557865446)]

将上传事件绑定在file的input里面,绑定方式就随意了。

var progress = $(".progress-bar"), status = $(".progress-bar-status"), percentVal = '0%'//上传步骤 $("#myupload").ajaxSubmit({ url: uploadUrl, type: "POST", dataType: 'json', beforeSend: function () { $(".progress").removeClass("hidden")progress.width(percentVal)status.html(percentVal)}, uploadProgress: function (event, position, total, percentComplete) { percentVal = percentComplete + '%'progress.width(percentVal)status.html(percentVal)console.log(percentVal, position, total)}, success: function (result) { percentVal = '100%'progress.width(percentVal)status.html(percentVal)//获取上传文件信息 uploadFileResult.push(result)// console.log(uploadFileResult)$(".upload-file-result").html(result.name)$("#upload-input-file").val('')}, error: function (XMLHttpRequest, textStatus, errorThrown) { console.log(errorThrown)$(".upload-file-result").empty()} })

[图片上传失败...(image-3d6ae0-1548557865446)]

[图片上传失败...(image-9f0adf-1548557865446)]

更多用法可以 参考官网

个主题化的进度条插件库的一切。

ProgressJs是一个JavaScript和CSS3库,帮助开发人员创建和管理页面上的任何对象的进度条。你可以自己设计模板的进度条或简单的定制。

你可以使用ProgressJs显示加载内容的进步(图像,视频,等等)到用户的网页。它可以用在所有的元素包括文本框,文本区,甚至整个身体。

它的重量轻,易于使用的,可定制的,自由和开放源码。

基本使用方法

//to set progress-bar for whole page

progressJs().start()

//or for specific element

progressJs("#targetElement").start()

这是ProgressJs的第一个测试版,这当然会更强大的很快。我们将发布一个稳定的变化版本,下载最新版本或其他。作为一个开发者,你可以帮助我们找到错误或解决他们自己的,开源的美。

加载图片动画

<div class="container" style="text-align: center">

<div class="row-fluid" style="margin-bottom: 30px">

<img class="span4 img-rounded" data-img="1" style="height: 187px" />

<img class="span4 img-rounded" data-img="2" style="height: 187px" />

<img class="span4 img-rounded