javascript - Preview image on popover, not displaying correctly -


can me popover image preview, problem upon hovering image preview wont display/update selected image.

this field upon hovering selected file image should display on popover. enter image description here

as can see below when hover first image gives me right imageenter image description here

but when hover next image should give me desert image still display previous image

enter image description here

however gives me right output when hover again enter image description here

here code popover

$('.example-popover').popover({                 trigger: 'hover',                 container: 'body',                 html: true,                 placement:'bottom',                 content: function () {                     var x = $(this).closest('div').find('#rawimage');                     if (x[0].files && x[0].files[0]) {                         var reader = new filereader();                          reader.onload = function (e) {                             $('#img-prview').attr('src', e.target.result);                         }                          reader.readasdataurl(x[0].files[0]);                     }                      return $('.img-container').html()                 }              }) 

here html

<div class="img-container hidden">         <img id="img-prview" src="#" style="width:50%"/>     </div>     <div class="form-group has-feedback">         <div class="row">             <div class="col-md-1">                 image             </div>             <div class="col-md-6">                 @html.textboxfor(m => m.rawimage, new { class = "form-control", placeholder = "image",type="file" })                 @html.validationmessagefor(m => m.rawimage, null, new { class = "text-danger" })                 <a href="#"><i class="fa fa-image example-popover"></i></a>             </div>         </div>     </div>     <div class="form-group has-feedback">         <div class="row">             <div class="col-md-1">                 image             </div>             <div class="col-md-6">                 @html.textboxfor(m => m.rawimage, new { class = "form-control", placeholder = "image",type="file" })                 @html.validationmessagefor(m => m.rawimage, null, new { class = "text-danger" })                 <a href="#"><i class="fa fa-image example-popover"></i></a>             </div>         </div>     </div> 

i hope can give me how can preview image on popover. thanks

i found solution this, has delay.

i think problem reader.onload returns img-container html first before changing img src.

so did

$('.example-popover').popover({                 trigger: 'hover',                 container: 'body',                 html: true,                 placement:'bottom',                 content: function () {                     var x = $(this).closest('div').find('#rawimage');                     var imgbyte = '';                     if (x[0].files && x[0].files[0]) {                         var reader = new filereader();                          reader.onload = function (e) {                             $('#previmg').attr('src', e.target.result);                         }                          reader.readasdataurl(x[0].files[0]);                     }                     return '<img id="previmg" src="#" style="width:100%"/>'                 }             })  

thanks everyone! hopes can reference someone!


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -