如何在dropzone中添加默认图像?

时间:2016-03-03 14:49:58

标签: javascript jquery dropzone.js

我有这个样本:

link

我想要做的是,当页面加载时,已经有一个带电图像

CODE JS:

Dropzone.autoDiscover = false;
var myDropzone = new Dropzone("div#myDrop", {
    acceptedFiles: "image/*",
    maxFiles:1,
    addRemoveLinks: true,
    init: function() {
        this.on("maxfilesexceeded", function(file){
            this.removeFile(file);
            alert("No more files please!");
        });
    },
    url: "#"
});

代码HTML:

<div class="dropzone dz-clickable" id="myDrop">
                                 <div class="dz-default dz-message" data-dz-message="">
                                      <span>Drag and upload your profile photo</span>
                                 </div>
                        </div>

是否有可能从第一张图片中加载图片?没有添加的用户

提前致谢!

1 个答案:

答案 0 :(得分:1)

Espero que te funcione,saludos。

    Dropzone.autoDiscover = false;
    var myDropzone = new Dropzone("div#myDrop", {
    acceptedFiles: "image/*",
    maxFiles:1,
    addRemoveLinks: true,
    init: function() {

            var thisDropzone = this;
            var mockFile = { name: 'Name Image', size: 12345, type: 'image/jpeg' };
            thisDropzone.emit("addedfile", mockFile);
            thisDropzone.emit("success", mockFile);
            thisDropzone.emit("thumbnail", mockFile, "https://goo.gl/IltWyB")

            this.on("maxfilesexceeded", function(file){
            this.removeFile(file);
            alert("No more files please!");
            });

          }, 
    url :  " # " 
});