How to implement an image popup in jquery for firebase

懵懂的女人 提交于 2019-12-06 09:33:51

Well, your question is not clear. However let me try to answer as per my understanding. If you want to display images in a popup, add a bootstrap modal to html, and on click of each image that you are displaying from firebase database,show the bootstrap modal as explained below:

Add this modal div to your HTML:

<div id="imageModal" class="modal fade" role="dialog">
  <div class="modal-dialog modal-sm">
     <div class="modal-content">
        <div class="modal-header">
           <button type="button" class="close" data-dismiss="modal">&times;</button>
           <h3 class="modal-title">Caption goes here..</h3>
        </div>
        <div class="modal-body">
           <div id="image"> </div>
        </div>
     </div>
  </div>

Now in your timeline.js file, add below code:

$('img').on('click', function () {
      $('#imageModal #image').empty();
      var imgUrl = $(this).attr('src');
      var caption = $(this).siblings('.contentCaption').html();
      $('#imageModal #image').append('<img width="100%" height="100%" src="' + imgUrl + '"></img>');
      $('#imageModal .modal-title').text(caption);
      $('#imageModal').modal('show');
   });

Note: There is a small error in your queryDatabase function:

var image = document.createElement("img");
image = document.createElement("div")
image.src = currentObject.url;

You are creating an image element and assigning the same variable to a div element. So, the image element is overwritten by div element. Delete the second statement image = document.createElement("div") for you to display the image element.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!