javascript - How to preview uploaded images?
滿天的星座
滿天的星座 2017-06-13 09:24:13
0
4
846

Similar to this kind of uploading pictures, you can also preview the display. How should I write the front end? Is there any similar code that you can provide me with? Thanks

滿天的星座
滿天的星座

reply all(4)
大家讲道理
var fr = new FileReader(),
    file = document.getElementById("file"),
    img = document.createElement("img");
file.onchange = function(e){
    fr.onload = function(e){
        var res = this.result;
        img.src = res;
        document.body.appendChild(img);//显示
    };
    
    fr.readAsDataURL(file.files[0]);//读取文件
};
左手右手慢动作

web uploader.js or FileReader API

扔个三星炸死你

I have written a preview of a mall product image before. The idea is very simple. I don’t know if it will be helpful to you:
1. The uploaded image must display a small thumbnail on the web page;
2. Backstage (we were In the background, you can also think of other ways) to store two pictures, a small thumbnail and a previewed high-definition large picture;
3. When you click on the small thumbnail, use a modal box to display the large high-definition picture.

给我你的怀抱

Two demos: Click event https://github.com/treeandgra...
Picture drag https://github.com/treeandgra...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template