Tuesday, 23 May 2017

How to show a div content in popup in facnybox


We assume that you already have added the fancybox js and css in your project



<html>

<div id="add_photo_notify_wrap">
    <div class="fancy_add_photo_notify_wrap">
        <div class="fancycontent">
            <p>This is my content sectioin.</p>
        </div>
        <div class="fancybtn">
            <a href="javascript:void(0)" class="btn add_photo_now">Add my photo now</a>
            <a href="javascript:void(0)" class="skip-it-now" onclick="$.fancybox.close();">Keep reviewing photos. I'll add my photo later.</a>
        </div>
    </div>
</div>

</html>

<script>

jQuery.fancybox({
  content: jQuery('#add_photo_notify_wrap').html(),
  modal: true,
  beforeShow: function(){
        jQuery(".fancybox-wrap").addClass('fancy_photo_notify');
    },
});

</script>

In this div id#add_photo_notify_wrap inner content will show in pop

and line jQuery(".fancybox-wrap").addClass('fancy_photo_notify'); will add class "fancy_photo_notify" to our popup

How to close Fancybox on anchor or button click

How to close Fancybox on anchor or button click

Nothing special to achieve this just siply write the fancybox close script inline with your tag just like

<a href="javascript:void(0)" onclick="$.fancybox.close();">Close</a>

or

<button onclick="$.fancybox.close();">Close</button>