JQuery implements file upload progress bar special effect _ jquery

Source: Internet
Author: User
Tags file upload progress bar
A file upload effect with a progress bar. Each file has a progress bar and upload details. The results are very good. We recommend it to you here. The upload progress bar is usually implemented by jquery and the backend Script script. Today we will introduce an example of how to implement the File Upload progress bar using basic php + jQuery. The details are as follows.

Recently, a project has made a progress bar, which has never been done before. It's just this week that there's nothing left. Let's use this to fill the number.

To upload a file, you must first prepare a "button ":

This looks good. The implementation is also very simple:

Start uploading filesIt's so ugly that we use span to make it more controllable. Add point css :. upload-span {display: inline-block; width: 120px; height: 40px; color: # FFFFFF; text-align: center; line-height: 40px; background-color: blue; border: 2px solid blue; border-radius: 5px; cursor: pointer; letter-spacing: 2px ;}

When you click it, the upload effect is triggered and an event is added.
A little more lifelike. You have to add a mask and a control that displays the progress bar. After you click span, the effect is like this:

 

Close

Confirm Cancellation

Add css:

.upload-mask{  position: absolute;  top: 0;  left: 0;  z-index: 9;  width: 100%;  height: 100%;  background-color: rgba(84,84,84,0.3);  display: none;}.upload-component{  position: absolute;  z-index: 99;  top: 50%;  left: 50%;  margin-left: -120px;  margin-top: -60px;  width: 240px;  height: 120px;  background-color: #FFFFFF;  display:none;}.upload-close{  position: relative;  height: 30px;  background-color: rgb(234,234,234);}.upload-close span{  position: absolute;  right: 15px;  line-height: 30px;  cursor: pointer;}.upload-content,.confirm-cancel{  margin-top: 15px;}.progress{  position:relative;  width:90%;  height:22px;  margin-left: 4.88888%;  text-align: center;  line-height: 22px;  /*background-color: blue;*/  border:1px solid #ccc;}.upload-text{  position:absolute;  z-index: 99999;  color:red;}.uploaded{  position:absolute;  left:0;  z-index: 9999;  width:0%;  height:100%;  background-color: blue;  color:#FFFFFF;}.confirm-cancel span{  display:inline-block;  width:60px;  height:30px;  line-height: 30px;  text-align: center;  /*cursor:pointer;*/  background-color:#ccc;  cursor:wait;}.confirm{  /*background-color: rgb(111,197,293);*/  margin-left:40%;}.cancel{  /*background-color: rgb(175,194,211);*/  margin-left: 10px;}

To simulate the progress display, two spans are used here:

The above one is used to show the percentage, and the following one is used to fill the color:

.upload-text{  position:absolute;  z-index: 99999;  color:red;}.uploaded{  position:absolute;  left:0;  z-index: 9999;  width:0%;  height:100%;  background-color: blue;  color:#FFFFFF;}

To be realistic, set the background color for the filled span, and its width is the percentage of the Progress. Finally, use js to simulate the progress change:

// Simulate progress function progressBar () {var max = 100; var init = 0; var uploaded; var test = setInterval (function () {init + = 10; uploaded = parseInt (init/max * 100) + '%'; extends uploadtextspan.text(uploaded).next().css ({width: uploaded}); if (init = 100) {clearInterval (test ); $ uploadTextSpan. text ('upload completed '); $ ('. confirm-cancel span'example .css ({cursor: 'pointer '}); background ({backgroundColor: 'rgb (111,197,293)'}); background ('.cancel'example .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 );}

JQuery implements the File Upload progress bar, which displays the upload percentage and other information. The content is here and I hope you will like it.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.