简体   繁体   English

单击图像时隐藏 div 并打开另一个 div

[英]Hide div and open another div when i click on the image

I have an image gallery and inside each image I have a div with the image name.我有一个图片库,在每个图片中我都有一个带有图片名称的 div。 When I click on an image a modal with some details is opened and the div with the image name is changed by the div with the tools.当我单击图像时,会打开带有一些详细信息的模式,并且带有图像名称的 div 会被带有工具的 div 更改。

What I want is that when closing the modal (just click outside it) everything returns to the original phase ie the div with the name replaces the div with the tools.我想要的是,当关闭模式时(只需在其外部单击),一切都会返回到原始阶段,即带有名称的 div 用工具替换 div。

Javascript Javascript

$(document).ready(function() {
  var toolbar = $('.ImageButtonsG').html();
  $(".d-block").each(function (index, value) {
    $(this).on("click", function(){
      var default_title = $(this).find('.ImageText');
      $(default_title).html(toolbar);
      $('.ImageButtonsG').empty();
    });
  });
});

I found problem with your JS code.我发现你的 JS 代码有问题。 Here is the updated code:这是更新的代码:

$(document).ready(function() {
  var toolbar = $('.ImageButtonsG').html();
  $(".d-block").on("click", function(){
      var default_title_ele = $(this).find('.ImageText');
      var default_title = $(default_title_ele).html();
      $(default_title_ele).html(toolbar);
      $("#myModal2").on('hidden.bs.modal', function () {
          $(default_title_ele).html(default_title);
      });
    });
});

Here is updated codepen .这是更新的codepen I hope it will solve your problem.我希望它能解决你的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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