iT邦幫忙

2018 iT 邦幫忙鐵人賽
DAY 19
1
Modern Web

30天學習30套前端技術(2018年)系列 第 19

[十分鐘學習] Fine Uploader - 拖曳上傳

  • 分享至 

  • xImage
  •  

example1

導入拖曳上傳檔案的好選擇,跨瀏覽器、原生JavaScript又加上百分百免費開源,只要載入一隻JavaScript就可以開始運作,不依賴其他程式

GitHub Star: 7,400
Javascripting Overall: 88%
瀏覽器: ChromeFirefoxIE10+
RWD: 不支援(可運作)
License: MIT


《安裝》

  • CDN

      <!-- jQuery v1.9.1 -->
      <script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
      <!-- Fine Uploader v5.15.5 -->
      <link href="https://cdnjs.cloudflare.com/ajax/libs/file-uploader/5.15.5/jquery.fine-uploader/fine-uploader.min.css" rel="stylesheet" />
      <link href="https://cdnjs.cloudflare.com/ajax/libs/file-uploader/5.15.5/all.fine-uploader/fine-uploader-gallery.min.css" rel="stylesheet" />
      <script src="https://cdnjs.cloudflare.com/ajax/libs/file-uploader/5.15.5/fine-uploader.min.js"></script>
      <script type="text/template" id="qq-template-gallery">
      	<div class="qq-uploader-selector qq-uploader qq-gallery" qq-drop-area-text="Drop files here">
      		<div class="qq-total-progress-bar-container-selector qq-total-progress-bar-container">
      			<div role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" class="qq-total-progress-bar-selector qq-progress-bar qq-total-progress-bar"></div>
      		</div>
      		<div class="qq-upload-drop-area-selector qq-upload-drop-area" qq-hide-dropzone>
      			<span class="qq-upload-drop-area-text-selector"></span>
      		</div>
      		<div class="qq-upload-button-selector qq-upload-button">
      			<div>Upload a file</div>
      		</div>
      		<span class="qq-drop-processing-selector qq-drop-processing">
      			<span>Processing dropped files...</span>
      			<span class="qq-drop-processing-spinner-selector qq-drop-processing-spinner"></span>
      		</span>
      		<ul class="qq-upload-list-selector qq-upload-list" role="region" aria-live="polite" aria-relevant="additions removals">
      			<li>
      				<span role="status" class="qq-upload-status-text-selector qq-upload-status-text"></span>
      				<div class="qq-progress-bar-container-selector qq-progress-bar-container">
      					<div role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" class="qq-progress-bar-selector qq-progress-bar"></div>
      				</div>
      				<span class="qq-upload-spinner-selector qq-upload-spinner"></span>
      				<div class="qq-thumbnail-wrapper">
      					<img class="qq-thumbnail-selector" qq-max-size="120" qq-server-scale>
      				</div>
      				<button type="button" class="qq-upload-cancel-selector qq-upload-cancel">X</button>
      				<button type="button" class="qq-upload-retry-selector qq-upload-retry">
      					<span class="qq-btn qq-retry-icon" aria-label="Retry"></span>
      					Retry
      				</button>
      				<div class="qq-file-info">
      					<div class="qq-file-name">
      						<span class="qq-upload-file-selector qq-upload-file"></span>
      						<span class="qq-edit-filename-icon-selector qq-edit-filename-icon" aria-label="Edit filename"></span>
      					</div>
      					<input class="qq-edit-filename-selector qq-edit-filename" tabindex="0" type="text">
      					<span class="qq-upload-size-selector qq-upload-size"></span>
      					<button type="button" class="qq-btn qq-upload-delete-selector qq-upload-delete">
      						<span class="qq-btn qq-delete-icon" aria-label="Delete"></span>
      					</button>
      					<button type="button" class="qq-btn qq-upload-pause-selector qq-upload-pause">
      						<span class="qq-btn qq-pause-icon" aria-label="Pause"></span>
      					</button>
      					<button type="button" class="qq-btn qq-upload-continue-selector qq-upload-continue">
      						<span class="qq-btn qq-continue-icon" aria-label="Continue"></span>
      					</button>
      				</div>
      			</li>
      			</ul>
      		<dialog class="qq-alert-dialog-selector">
      			<div class="qq-dialog-message-selector"></div>
      			<div class="qq-dialog-buttons">
      				<button type="button" class="qq-cancel-button-selector">Close</button>
      			</div>
      		</dialog>
      		<dialog class="qq-confirm-dialog-selector">
      			<div class="qq-dialog-message-selector"></div>
      			<div class="qq-dialog-buttons">
      				<button type="button" class="qq-cancel-button-selector">No</button>
      				<button type="button" class="qq-ok-button-selector">Yes</button>
      			</div>
      		</dialog>
      		<dialog class="qq-prompt-dialog-selector">
      			<div class="qq-dialog-message-selector"></div>
      			<input type="text">
      			<div class="qq-dialog-buttons">
      				<button type="button" class="qq-cancel-button-selector">Cancel</button>
      				<button type="button" class="qq-ok-button-selector">Ok</button>
      			</div>
      		</dialog>
      	</div>
      </script>	
    
  • npm

      $ npm install fine-uploader 
    

《範例》

  • 包含拖曳和限制圖檔的上傳功能

      <div id="example"></div>
      <script>
      	var galleryUploader = new qq.FineUploader({
      		element: document.getElementById( "example" ), // 目標物件
      		template: "qq-template-gallery", // 模板物件
      		request: {
      			endpoint: "/server/uploads" // 上傳位置
      		},
      		thumbnails: {
      			placeholders: {
      				waitingPath: "https://cdnjs.cloudflare.com/ajax/libs/file-uploader/5.15.5/all.fine-uploader/placeholders/waiting-generic.png", // 讀取中
      				notAvailablePath: "https://cdnjs.cloudflare.com/ajax/libs/file-uploader/5.15.5/all.fine-uploader/placeholders/not_available-generic.png" // 路徑無效
      			}
      		},
      		validation: {
      			allowedExtensions: [ "jpeg", "jpg", "gif", "png" ] // 支援檔案類型
      		}
      	});
      </script>
    

《延伸》

  1. Fine Uploader Javascript Upload Library
  2. FineUploader/fine-uploader: Multiple file upload plugin with image previews, drag and drop, progress bars. S3 and Azure support, image scaling, form support, chunking, resume, pause, and tons of other features.

上一篇
[十分鐘學習] Intro.js - 網站導覽
下一篇
[十分鐘學習] Parallax - 某站做出視覺效果竟然是靠它
系列文
30天學習30套前端技術(2018年)61
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言