Html5之图片拖放上传
转载:提升用户体验:HTML5 拖放文件上传
http://gandli.blog.163.com/blog/static/3084958420101023274347/
<!DOCTYPE HTML><html><head><meta charset="utf-8"> <title>HTML5 浏览器拖放 | HTML5 Drag and drop</title> <style>#section{font-family: "Georgia", "微软雅黑", "华文中宋";} .container{display:inline-block;min-height:200px;min-width:360px;color:#f30;padding:30px;border:3px solid #ddd;-moz-border-radius:10px;-webkit-border-radius:10px;border-radius:10px;}.preview{max-width:360px;}#files-list{position:absolute;top:0;left:500px;}#list{width:460px;}#list .preview{max-width:250px;}#list p{color:#888;font-size:12px;}#list .green{color:#09c;} </style></head><body> <div id="section"> <p>把你的图片拖到下面的容器内:</p> <div id="container" src="' + e.target.result + '" title="' + theFile.name + '"/>';looks(theFile, img);};})(f)reader.readAsDataURL(f);} else {img = '"o((>ω< ))o",你传进来的不是图片!!';looks(f, img);}}}// 处理插入拖出效果function handleDragEnter(evt){ this.setAttribute('style', 'border-style:dashed;'); }function handleDragLeave(evt){ this.setAttribute('style', ''); }// 处理文件拖入事件,防止浏览器默认事件带来的重定向function handleDragOver(evt) {evt.stopPropagation();evt.preventDefault();}cnt.addEventListener('dragenter', handleDragEnter, false);cnt.addEventListener('dragover', handleDragOver, false);cnt.addEventListener('drop', handleFileSelect, false);cnt.addEventListener('dragleave', handleDragLeave, false);} else {document.getElementById('section').innerHTML = '你的浏览器不支持啊,同学';}</script> </body></html>