我的目标是为视频和图像设置拖放上传框,以将文件填充到框的确切形状和大小。Js通过预览功能拖放图像/视频上传
您可以在这里看到的片段:http://jsfiddle.net/ELcf6/4/
想不通,如何为视频上传相同的功能添加到同一个盒子。将不胜感激任何帮助。
这里的片段:
var imageLoader = document.getElementById('filePhoto');
imageLoader.addEventListener('change', handleImage, false);
function handleImage(e) {
var reader = new FileReader();
reader.onload = function (event) {
$('.uploader img').attr('src',event.target.result);
}
reader.readAsDataURL(e.target.files[0]);
}
.uploader {position:relative; overflow:hidden; width:300px; height:350px; background:#f3f3f3; border:2px dashed #e8e8e8;}
#filePhoto{
position:absolute;
width:300px;
height:400px;
top:-50px;
left:0;
z-index:2;
opacity:0;
cursor:pointer;
}
.uploader img{
position:absolute;
width:302px;
height:352px;
top:-1px;
left:-1px;
z-index:1;
border:none;
}
<div class="uploader" onclick="$('#filePhoto').click()">
click here or drag here your images for preview and set userprofile_picture data
<img src=""/>
<input type="file" name="userprofile_picture" id="filePhoto" />
</div>
因此,这是一个建议,而不是修复/答案不应该被发布为评论,而不是答案? – NewToJS