Fancybox afterClose event not working

前端 未结 3 1992
忘了有多久
忘了有多久 2021-01-14 23:41

I\'m having a problem using the fancybox API after Close.

I open the function when people click on this:



        
相关标签:
3条回答
  • 2021-01-14 23:59

    Some clarification to avoid further confusion:

    Based on your html

    <a class="fancybox fancybox.iframe btn" href="myurl.php"></a>
    
    1. Use the afterClose callback (not an event) instead of beforeClose. For further reference check Tips & Tricks => No.11

    2. The class fancybox is used to bind the selector to fancybox so your initialization code should look like this

      jQuery(document).ready(function ($) {
          $('.fancybox').fancybox({
              arrows: false,
              padding: 0,
              helpers: {
                  overlay: {
                      locked: false
                  }
              },
              afterClose: function () {
                  location.reload();
              }
          });
      }); // ready
      
    3. The (valid) fancybox.iframe class tells fancybox the type of content it should handle, but you don't use it to bind the selector to fancybox.

    See JSFIDDLE

    NOTE : this is for fancybox v2.x

    0 讨论(0)
  • 2021-01-15 00:07

    Try using onClose event:

    $('.fancybox.iframe')
    .fancybox({
        arrows : false,
        padding: 0,
        overlay: {
            locked: false
        },
        onClosed: function() {
            location.reload(); 
        }
    
    });
    

    According to the API there is no beforeClose event, but there is onClose

    http://fancybox.net/api

    0 讨论(0)
  • 2021-01-15 00:11

    You should use

    $('.fancybox.iframe').fancybox({
        arrows: false,
        padding: 0,
        helpers: { overlay : {closeClick: false} },
        beforeClose: function () {
            parent.location.reload(true);
        }
    });
    

    (Note that the syntax is different between version 1 and 2 of fancybox. The above is for fancybox2)

    0 讨论(0)
提交回复
热议问题