我使用 CSS background-image
预览拍摄的照片。 (不是<img src="">
)
HTML:
<div class="image"></div>
<input type="file" name="upload" id="upload" accept="image/*">
<label for="upload">Upload</label>
CSS:
.image {
position: absolute;
top: 0;
left: 0;
width: 300px;
height: 300px;
background-size: 100%;
background-size: cover;
}
JS:
function readImage(el) {
if (el.files && el.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
var base64 = e.target.result;
$('.image').css('background-image', 'url(' + base64 + ')');
};
reader.readAsDataURL(el.files[0]);
}
}
$('#upload').change(function() {
readImage(this);
});
拍摄照片时,预览会在移动版Safari 上显示错误的方向。谁知道如何解决?任何伎俩?