HTML5 CSS3 經典案例:無外掛程式拖拽上傳圖片 (支援預覽與批量) (一)

來源:互聯網
上載者:User

轉載請標明出處:http://blog.csdn.net/lmj623565791/article/details/31498319

上傳基本是項目中經常出現的,一般採用:

1、form提交 

2、flash

3、html5

form提交會重新整理頁面,很難做到非同步上傳;flash可能是用得比較多了,因為可以兼顧到幾乎所有的瀏覽器,我之前一直會用jquery的uploadify作為項目中的上傳工具,uploadify也有基於html5好像是收費的,大家可以去官網看看;當然了,現在html5提供了API以及File,FileReader,XMLHttpRequest等強大的API,為我們拖放實現上傳提供了可能。

1:


2:


由於本地上傳實在太快,錄了個80M的gif,終於可以看到上傳的細節效果了,是不是還是很不錯的,建議CSDN的部落格編輯器也支援下拖拽上傳,省的我去找檔案了。

由於代碼比較多:

這一片主要講一下HTML和CSS:

HTML代碼:

<!DOCTYPE html><html><head>    <title></title>    <meta charset="utf-8"/>    <link href="reset.css" type="text/css" rel="stylesheet"/>    <link href="01.css" type="text/css" rel="stylesheet"/></head><body><div id="uploadBox">    <ul>        <li>            <img src="images/pic1.jpg"/>            <span class="progress"></span>            <span class="percentage"></span>        </li>        <li>            <img src="images/pic2.jpg"/>            <span class="progress"></span>            <span class="percentage">12%</span>        </li>        <li class="done">            <img src="images/pic2.jpg"/>            <span class="progress"></span>            <span class="percentage"></span>        </li>        <div class="clearfix"></div>    </ul></div></body></html>

還是很簡潔的:

a、一個div#uploadBox,裡面ul li 代表每個上傳圖片單元

b、li img 圖片

c、li span.progress用於顯示進度,有種水上漲的效果,從height:0% -100%;

d、li span.percentage 用於在圖片中央顯示 1% 到100%數字,當到達100%時,顯示一個正確的圖片


CSS:

body{    background: #eee;}#uploadBox{    width: 622px;    height: 362px;    background-color: #fff;    border: 1px solid #777;    margin: 120px auto;}#uploadBox ul li{    float: left;    position: relative;    margin-left: 5px;    margin-top: 5px;}#uploadBox  li img{    border: 1px solid #D1D1D1;    width: 198px;    height: 112px;    vertical-align: middle;}#uploadBox  li  .percentage{    width: 69px;    height: 69px;    position: absolute;    left: 50%;    top: 50%;    margin-left: -34.5px;    margin-top: -34.5px;    text-align: center;    font-size: 18px;    line-height: 69px;    color: #fff;    border-radius: 34.5px;    background: rgba(0, 0, 0, .8);}#uploadBox  li.done .percentage{    background: url("images/done.png") no-repeat 0 0;    text-indent: -1000em;}#uploadBox li .progress{    position: absolute;    height: 22.4px;    bottom: 0px;    width: 200px;    background: #000;    opacity: .5;}.clearfix{    clear: both;}

都是比較簡單的,基本就是定位的簡單使用~大家自己看下~

最後:



歡迎大家留言~如果有什麼想法,或者好的案例~





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.