jQuery實(shí)現(xiàn)簡單的文件上傳進(jìn)度條效果
本文實(shí)例講述了jQuery實(shí)現(xiàn)文件上傳進(jìn)度條效果的代碼。分享給大家供大家參考。具體如下:
運(yùn)行效果截圖如下:
具體代碼如下:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>upload</title> <link rel="stylesheet" type="text/css" href="upload/upload.css"> <script type="text/javascript" src="upload/jquery.js"></script> </head> <body> <span class="upload-span">開始上傳文件</span> <div class="upload-mask"></div> <div class="upload-component"> <div class="upload-close"> <span class="upload-close-span">關(guān)閉</span> </div> <div class="upload-content"> <div class="progress"> <span class="upload-text"></span> <span class="uploaded"></span> </div> <div class="confirm-cancel"> <span class="confirm">確認(rèn)</span> <span class="cancel">取消</span> </div> </div> </div> <script type="text/javascript" src="upload/upload.js"></script> </body> </html>
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; } .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; 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; background-color:#ccc; cursor:wait; } .confirm{ margin-left:40%; } .cancel{ margin-left:10px; }
jQuery代碼:
$(function (){ var $uploadSpan = $('.upload-span'); var $uploadMask = $('.upload-mask'); var $uploadContent = $('.upload-component'); var $closeConfirmCancel = $('.upload-close-span,.confirm,.cancel'); var $uploadTextSpan = $('.upload-text'); function showMask(){ $(".upload-mask,.upload-component").css({display:'block'}); progressBar(); $uploadSpan.off('click',showMask); } function hiddenMask(){ $uploadMask.css({display:'none'}); $uploadSpan.on('click',showMask); } function closeConfirmCancel(){ $uploadContent.css({display:'none'}); $uploadTextSpan.text('').next().css({width:0}); hiddenMask(); } // 模擬進(jìn)度 function progressBar(){ var max =100; var init =0; var uploaded; var test = setInterval(function(){ init +=5; 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(); }); } },1000); } $uploadSpan.on('click',showMask); })
JQuery實(shí)現(xiàn)文件上傳進(jìn)度條,能顯示上傳的百分比等信息,內(nèi)容就到這里了,希望大家能夠喜歡。
相關(guān)文章
基于jQuery通過jQuery.form.js插件實(shí)現(xiàn)異步上傳
這篇文章主要介紹了基于jQuery通過jQuery.form.js插件實(shí)現(xiàn)異步上傳,代碼很詳細(xì),感興趣的小伙伴們可以參考一下2015-12-12jquery心形點(diǎn)贊關(guān)注效果的簡單實(shí)現(xiàn)
下面小編就為大家?guī)硪黄猨query心形點(diǎn)贊關(guān)注效果的簡單實(shí)現(xiàn)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-11-11jQuery簡單實(shí)現(xiàn)上下,左右滑動(dòng)的方法
這篇文章主要介紹了jQuery簡單實(shí)現(xiàn)上下,左右滑動(dòng)的方法,涉及jQuery動(dòng)態(tài)操作頁面元素的相關(guān)技巧,需要的朋友可以參考下2016-06-06Jquery Uploadify多文件上傳帶進(jìn)度條且傳遞自己的參數(shù)
Jquery Uploadify多文件上傳帶進(jìn)度條且傳遞自己的參數(shù),具體實(shí)現(xiàn)如下,需要的朋友可以學(xué)習(xí)下2013-08-08jquery實(shí)現(xiàn)移動(dòng)端按鈕組左右滑動(dòng)
這篇文章主要為大家詳細(xì)介紹了jquery實(shí)現(xiàn)移動(dòng)端按鈕組左右滑動(dòng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03javascript 自定義回調(diào)函數(shù)示例代碼
使用函數(shù)做參數(shù)就有下面的好處:當(dāng)你a(b)的時(shí)候函數(shù)b就成了回調(diào)函數(shù),而你還可以a(c)這個(gè)時(shí)候,函數(shù)c就成了回調(diào)函數(shù)2014-09-09jquery Ajax 實(shí)現(xiàn)加載數(shù)據(jù)前動(dòng)畫效果的示例代碼
本篇文章主要是對jquery Ajax實(shí)現(xiàn)加載數(shù)據(jù)前動(dòng)畫效果的示例代碼進(jìn)行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助2014-02-02jQuery中attr()和prop()在修改checked屬性時(shí)的區(qū)別
使用語句$.attr('checked',true),將復(fù)選框的屬性改為被選中,在chrome瀏覽器中第一次點(diǎn)擊有效后面就不行了,IE8倒是沒有問題2014-07-07jquery操作checkbox的常用方法總結(jié)【附測試源碼下載】
這篇文章主要介紹了jquery操作checkbox的常用方法,結(jié)合完整實(shí)例形式總結(jié)分析了jQuery使用checkbox全選、取消、反選等常見操作技巧,并附帶測試源碼供讀者下載參考,需要的朋友可以參考下2019-06-06