javascriptfancybox

remove the class after closing fancybox 4


in version 3 it was like this:

$("[data-fancybox]").fancybox({
    afterClose: function () {
        //window.location.reload();
        $(".modal-content").removeClass("active");
    },
});

How to write the same in version 4?


Solution

  • Fancybox.bind('[data-fancybox]', {
     on: {
      destroy: function (fancybox, event) {
       document.querySelectorAll('.modal-content').forEach(function (content) {
        content.classList.remove('active');
       });
      },
     },
    });