0

In FancyBox2 I want to prevent bubbling of a element inside an element.
On both elements there is fancybox attached.
But if you click on the the inner element the outer element also fired.
How can I stop the event-bubbling?

HTML :

<div class="outside" data-fancybox-href="#content">OUT
    <div class="inside" data-fancybox-href="#content">IN</div>
</div>
<div id="content">content</div>

CSS :

.outside {
    background :yellow;
    height:100px;
    width:100px;
}
.inside {
    background : orange;
    height:50px;
    margin:0 25px;
    width:50px;
}

#content
{
    display:none;
}

JS :

jQuery(".outside").fancybox({
    beforeLoad: function () {
        alert("outside");
    }
});

jQuery(".inside").fancybox({
    beforeLoad: function () {
        alert("inside");
    }
});

Here is an example : http://jsfiddle.net/zrH6g/

EDIT 1
Fixed it by loading the content and with clicks http://jsfiddle.net/483uM/2/

EDIT 2
Edit 1 was a solution but it wasn't working since the content(DOM Elements) were copied and not moved. FancyBox 1 copies and paste the DOM Elements.
FancyBox 2 Moves it and puts it back(Cut/Paste).

What I've done now is I created a new div and click on that and remove it when fancybox closes.

//Results Cup
    jQuery('.beakerLink').click(function(event)
    {
        //Stop Default + Event Bubbling
        event.preventDefault();
        event.stopPropagation();

        //Set CSS Class + DataFancyBoxHref
        var fancyBoxRemoveCssClass = "NEED_TO_HIDE_THIS_AFTER_FANCYBOX_CLOSE";
        var dataFancyBoxHref = jQuery(this).attr("data-fancybox-href");

        //Dirty FIX : Add div to click for beaker link
        //Reason : Can't prevent event bubbling of beaker
        jQuery(".kalender_overview").append("<div class='" + fancyBoxRemoveCssClass + "' data-fancybox-href='" + dataFancyBoxHref + "'>REMOVE AFTER FANCYBOX CLOSES</div>");

        //Init FancyBox
        jQuery("." + fancyBoxRemoveCssClass).fancybox(
        {
            //Before Closing
            beforeClose: function()
            {
                //Remove Created Temp Div Element (Dirty FIX)
                jQuery("." + fancyBoxRemoveCssClass).remove();
            }
        });

        //Click
        jQuery("." + fancyBoxRemoveCssClass).click();
    });
4

0 回答 0