简体   繁体   English

如何使用AJAX调用jQuery Lightbox

[英]How to call jQuery Lightbox with AJAX

How can I call jQuery Lightbox2 with AJAX. 如何使用AJAX调用jQuery Lightbox2。

I am using this function for my project. 我正在为我的项目使用此功能。

$(document).ready(function() {
    $(".paylasimi-goster").click(function() {
        event.preventDefault();
        var id = $(this).data("id");
        $.ajax({
            url: "gonderiyi_goster.php?msg_id=" + id,
            type: 'get',
            beforeSend: function() {
                $("#loader").fadeIn(100);
            },
        }).done(function(data) {
            $("#loader").fadeOut(100);
            $(".sidebar").fadeIn().find(".sidebar-content").animate({
                "right": 0
            }, 200).html(data);
            imgResize(jQuery, 'smartresize');
        });
    });

    $(".sidebar").click(function() {
        $(".sidebar-content").animate({
            "right": "-565px"
        }, 200, function() {
            $(".sidebar").fadeOut();
        })

    });
    $(".sidebar-content").click(function(e) {
        e.stopPropagation();
    });
});

Also I have created this DEMO from jsfiddle. 我也从jsfiddle创建了这个DEMO In this jsfiddle you can see there white div. 在这个jsfiddle中,您可以看到白色div。 Click any white div then see the right sidebar. 单击任何白色div,然后查看右侧边栏。 So in the sidebar have one image. 因此,在侧边栏中只有一张图像。 The problem is here : Lightbox2 does not work when you click on the image. 问题出在这里:单击图像时Lightbox2不起作用。

How can I call Lightbox2 with ajax. 如何使用Ajax调用Lightbox2。

The issue here is the e. stopPropagation() 这里的问题是e. stopPropagation() e. stopPropagation() on the .sidebar-content click event which is preventing the lightbox from triggering. .sidebar-content click事件上的e. stopPropagation()阻止灯箱触发。 You can remove that altogether and inside the .sidebar click event instead call: 您可以将其完全删除,并在.sidebar click事件内调用:

$(".sidebar").click(function(e){
     var preventClick = $(".sidebar-content");

     if (!preventClick.is(e.target) && preventClick.has(e.target).length === 0){
       //run the hide animate function + callback 
       $(".sidebar-content").animate({"right":"-200px"},200,function(){
           $(".sidebar").fadeOut();   
       });
     };     
});

FIDDLE 小提琴

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

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