jquery鼠标拖拽多文件上传插件

所属分类: 网页特效-图片特效&上传    2023-08-24 10:57:51

jquery鼠标拖拽多文件上传插件 ie兼容6
反馈问题  查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

jquery鼠标拖拽多文件上传插件(共5个文件)

    • index.html

使用方法

'use strict';

jQuery.fn.extend({

	bs_dropzone: function (options) {

		let $group, $element, $area, $box, $input, $preview, $line, $column, $image, defaults, files, flag, reader, extension;

		defaults = {
			preview: false,
			allowed: ['jpg', 'jpeg', 'png', 'bmp', 'webp', 'jfif', 'svg', 'ico', 'gif'],
			accepted: [],
			dropzoneTemplate: '<div class="bs-dropzone"><div class="bs-dropzone-area"></div><div class="bs-dropzone-message"></div><div class="bs-dropzone-preview"></div></div>',
			parentTemplate: '<div class="row"></div>',
			childTemplate: '<div class="col"></div>',
			boxClass: 'alert text-center',
			imageClass: 'img-fluid',
			noneColorClass: 'alert-info',
			dragColorClass: 'alert-warning',
			doneColorClass: 'alert-success',
			failColorClass: 'alert-danger',
			language: {
				emptyText: '[将文件拖到此处或单击上传]',
				dragText: '[将文件拖到此处]',
				dropText: '[_t_ File(s)]'
			},
			change: function () {}
		};

		options = $.extend({}, defaults, options);
		$group = this;

		$group.each(function (i) {

			$element = $(this);
			if ($element.attr('accept') == undefined && options.accepted.length > 0) {
				$element.attr('accept', '.' + options.accepted.join(', .'));
			}
			$element.after(options.dropzoneTemplate);
			$element.appendTo($element.next().find('.bs-dropzone-area'));
			$area = $('<div></div>');
			$area.attr('class', 'bs-dropzone-box ' + options.boxClass + ' ' + options.noneColorClass).text(options.language.emptyText);
			$element.before($area);

			$element.on('dragover', function () {

				$(this).prev().attr('class', 'bs-dropzone-box ' + options.boxClass + ' ' + options.dragColorClass).text(options.language.dragText);
			
			}).on('dragleave drop', function () {

				$input = $(this);
				files = this.files;
				$input.prev().attr('class', 'bs-dropzone-box ' + options.boxClass + ' ' + options.noneColorClass).text((files.length > 0) ? (options.language.dropText.replace(/_t_/g, files.length)) : options.language.emptyText);
				$input.trigger('blur');

			}).on('change', function () {

				$input = $(this);
				$input.trigger('preview');
				$input.trigger('blur');
				options.change.call(this, $input, this.files);

			}).on('preview', function () {

				$input = $(this);
				$box = $input.prev();
				$preview = $input.closest('.bs-dropzone').find('.bs-dropzone-preview');
				$preview.empty();
				files = this.files;
				flag = false;
				if (files.length > 0) {
					if (options.preview) {
						$line = $(options.parentTemplate);
						$.each(files, function (i) {
							extension = files[i].name.match(/\.[0-9a-z]+$/i);
							extension = (extension) ? extension[0].split('.').pop().toLowerCase() : null;
							if ($.inArray(extension, options.allowed) + 1 > 0) {
								reader = new FileReader();
								reader.onload = function (e) {
									$image = $('<img src="' + e.target.result + '" class="' + options.imageClass + '">');
									$column = $image.wrap(options.childTemplate).parent();
									$column.appendTo($line);
								}
								reader.readAsDataURL(this);
								flag = true;
							}
						});
						if (flag) {
							$line.appendTo($preview);
							$preview.show();
						}
					}
					$box.text(options.language.dropText.replace(/_t_/g, files.length));
				} else {
					$preview.hide();
					$box.text(options.language.emptyText);
				}

			}).on('clear', function () {

				$input = $(this);
				$box = $input.prev();
				$preview = $input.closest('.bs-dropzone').find('.bs-dropzone-preview');
				$box.attr('class', 'bs-dropzone-box ' + options.boxClass + ' ' + options.noneColorClass).text(options.language.emptyText);
				$preview.empty();
				$preview.hide();

			}).on('validation', function (event, state) {

				$input = $(this);
				$box = $input.prev();
				$preview = $input.closest('.bs-dropzone').find('.bs-dropzone-preview');
				if (state) {
					$box.attr('class', 'bs-dropzone-box ' + options.boxClass + ' ' + options.doneColorClass);
				} else {
					$box.attr('class', 'bs-dropzone-box ' + options.boxClass + ' ' + options.failColorClass);
					$preview.hide();
				}
				$input.css('height', $box.outerHeight());

			});

			$element.closest('form').on('reset', function () {

				$(this).find(':file').each(function () {

					$(this).trigger('clear');

				});

			});

		});

	}

});

站长提示:
1. 平台上所有素材资源,需注册登录会员方能正常下载。
2. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励20K币
3. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
4. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 图片特效&上传

jquery动画3d轮询切换幻灯片轮播插件

文本标签内容3D动画切换,有点类似于标签球,大家试试吧!
  图片特效&上传
 118  

HTML5+Canvas创建的交互式多功能图片查看器

一款图片预览查看工具,提供的功能包含:图片平移、旋转、镜像和翻转等操作,很实用的一款工具。
  图片特效&上传
 119  

html5图片堆栈布局点击加载更多图片效果

多张图片无规则堆叠的状态,点击下拉箭头动画排列!
  图片特效&上传
 191  

jquery鼠标悬停图片向上/向下平滑滚动特效插件

一款鼠标悬停图片滚动器插件,鼠标悬停在图片区域上触发平滑缓慢的上下滚动特效。
  图片特效&上传
 186  

评论数(1) 回复有机会获得K币 用户协议

    铁头de科技0
    2024-01-18 20:04:35
    多文件上传刚好能用上,感谢苦力吧
    回复
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论