简体   繁体   中英

Dropzone.js CSS

I have a upload by dropzone.js . I added the next code to my JS:

 thumbnail: function(file, dataUrl) {
    var thumbnail = $('.dropzone .dz-preview.dz-file-preview .dz-image:last');
    thumbnail.css('background', 'url('+dataUrl+')');
    var $fotoramaDiv = $('.fotorama').fotorama();
    var fotorama = $fotoramaDiv.data('fotorama');
    fotorama.push({img: dataUrl, thumb:dataUrl});   
 }

I have only one problem - when I upload more than one picture at the same time I get only the last picture.

图片

This is the situation if I remove :last image2

How can I solve this?

SOLVED!

Your thumbnail selector $('.dropzone .dz-preview.dz-file-preview .dz-image:last'); is reffered to only the :last element. You should remove the :last pseudoclass.

form

<form action="/file-upload"
  class="dropzone"
  id="my-awesome-dropzone"></form>

JS

 thumbnail: function("#my-awesome-dropzone") {
var thumbnail = $('.dropzone .dz-preview.dz-file-preview');
thumbnail.css('background', 'url('+dataUrl+')');
var $fotoramaDiv = $('.fotorama').fotorama();
var fotorama = $fotoramaDiv.data('fotorama');
fotorama.push({img: dataUrl, thumb:dataUrl});   

}

JSFIDDLE - https://jsfiddle.net/gqbkhkxp/

I did the next:

thumbnail: function(file, dataUrl) {
        var i=sessionStorage.getItem('uploaded_pic');
        if(typeof(dataUrl) != "undefined" && dataUrl !== null) {
            i++;
            sessionStorage.setItem('uploaded_pic', i);
            var selector='.dropzone .dz-preview.dz-file-preview:nth-child('+i+') .dz-image';
            alert(selector);
            var thumbnail = $(selector);
            thumbnail.css('background', 'url('+dataUrl+')');
            var $fotoramaDiv = $('.fotorama').fotorama();
            var fotorama = $fotoramaDiv.data('fotorama');
            fotorama.push({img: dataUrl, thumb:dataUrl});
        }

And when the page is loaded I going to always reset the session storage:

sessionStorage.setItem('uploaded_pic', 1);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM