【发布时间】:2020-11-13 18:07:08
【问题描述】:
so I have a file button that lets a user select a video to upload it and another button that uploades the video but when a video is selected a preview has to appear before it is uploaded.问题是,即使没有选择视频,视频应该在哪里也有很多空间,目标是如果没有点击视频按钮,那么视频应该显示:没有,但如果点击了,那么视频也出现了。就像facebook的视频或图片预览。
const realFileBtn = document.getElementById("id_video");
const customBtn = document.getElementById("custom-b");
customBtn.addEventListener("click", function() {
realFileBtn.click();
});
$(document).on("change", ".file_multi_video", function(evt) {
var $source = $('#video_here');
$source[0].src = URL.createObjectURL(this.files[0]);
$source.parent()[0].load();
});
input {
border: none;
order: 0;
font-family: sans-serif;
padding: 5px;
border-radius: 7.5px;
width: 100%;
height: 35px;
display: flex;
}
#custom-b {
border: none;
font-family: sans-serif;
padding: 5px;
order: 1;
border-radius: 7.5px;
width: 15%;
display: flex;
justify-content: center;
}
.preview-image {
width: 100%;
height: 100%;
display: flex;
order: 0;
padding-top: 8px;
padding-bottom: 8px;
align-self: center;
}
.uploades .submit-button {
border: none;
font-family: sans-serif;
padding: 5px;
order: 2;
display: flex;
border-radius: 7.5px;
width: 100%;
margin-top: 16px;
justify-content: center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
<input type="text" name="text" placeholder="Add a comment..." required="" id="id_text">
<input type="file" name="video" id="id_video" accept="video/*" class="file_multi_video" style="display: none;">
<video id="blah" class="preview-image">
<source id="video_here">
</video>
<button type="button" class="video-button" id="custom-b">video</button>
</div>
<button class="submit-button" type="submit">Save</button>
有任何问题请告诉我;)
【问题讨论】:
标签: javascript html jquery css django