简体   繁体   English

图像叠加单击关闭

[英]Image overlay click off

I was following this fiddle link to add an overlay to make an image bigger.我正在按照这个小提琴链接添加一个叠加层以使图像更大。 In it though you have to click the enlarged image again to close the overlay.尽管您必须在其中再次单击放大的图像才能关闭叠加层。 I was wondering if I could reverse it and only be able to click off the image?我想知道我是否可以将其反转并且只能单击图像?

I would assume it's in the jquery here:我假设它在 jquery 中:

        $(".brick img").click(function() {
          $("#imgBig").attr("src", $(this).prop('src'));
          $("#overlay").show('slow');
          $("#overlayContent").show('slow');
        });

        $("#imgBig").click(function() {
          $("#imgBig").attr("src", "");
          $("#overlay").hide();
          $("#overlayContent").hide();
        });

From what I understood, you want it to remove the image if the user clicks the background overlay and not the image, so try this:据我了解,如果用户单击背景覆盖而不是图像,您希望它删除图像,所以试试这个:

    $(".brick img").click(function(){                                             $("#imgBig").attr("src",$(this).prop('src'));
    $("#overlay").show('slow');
    $("#overlayContent").show('slow');
});

$("#overlay").click(function(){
    $("#imgBig").attr("src", "");
    $("#overlay").hide();
    $("#overlayContent").hide();
});
$("#overlayContent").click(function(){
    $("#imgBig").attr("src", "");
    $("#overlay").hide();
    $("#overlayContent").hide();
});
   

since the #overlay is overridden by the #overlayContent I added a 2nd function that does the same thing if the overall background area is clicked, it will remove the image, instead of having to click the image itself.由于#overlay 被#overlayContent 覆盖,我添加了第二个function,如果单击整个背景区域,它会执行相同的操作,它将删除图像,而不必单击图像本身。

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

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