Jquery - fancybox and callback

前端 未结 7 1609
借酒劲吻你
借酒劲吻你 2020-12-31 17:36

I have problem with fancybox.
I want to write a function that will run when the fancybox opened. How and when to call the function?

Example:

func         


        
相关标签:
7条回答
  • 2020-12-31 17:43

    The newest way how to make it work is using afterShow or beforeShow:

    $("a#registrace").fancybox({
      beforeShow   : function() {
        alert('its working!');
        validate_reg_form();
      }
    });
    

    I am loading registration form through ajax and I need to enable form-validation. In both cases (before and after), the content is already loaded.

    0 讨论(0)
  • 2020-12-31 17:53

    Actually, on checking the docs, you have a typo in your option list...

    You have callBackOnShow but it should be callbackOnShow (lower case b)

    0 讨论(0)
  • 2020-12-31 17:54

    It should be:-

    function myFunc() {
        alert("Opened!");
    }
    
    $('.content a').fancybox({ 
        'hideOnContentClick': false ,
        'callBackOnShow': myFunc, // no brackets
        'frameWidth': 920,
        'frameHeight': 530
    });
    

    Or, you can make an anonymous function...

    $('.content a').fancybox({ 
        'hideOnContentClick': false ,
        'callBackOnShow': function() { alert('hello'); },
        'frameWidth': 920,
        'frameHeight': 530
    });
    
    0 讨论(0)
  • 2020-12-31 17:59

    This works

    $("#element").fancybox({
        onStart     :   function() {
            return window.confirm('Continue?');
        },
        onCancel    :   function() {
            alert('Canceled!');
        },
        onComplete  :   function() {
            alert('Completed!');
        },
        onCleanup   :   function() {
            return window.confirm('Close?');
        },
        onClosed    :   function() {
            alert('Closed!');
        }
    });
    
    0 讨论(0)
  • 2020-12-31 18:00

    As your title says "Jquery - fancybox and callback", You can a complete list of callback options for the fancybox 2 plugin found under the tab callbacks.

    http://fancyapps.com/fancybox/#docs

    If your using the old fancybox, maybe upgrading to fancybox2 as the new plugin has better features, with more control.

    0 讨论(0)
  • 2020-12-31 18:02

    Instead of myFunc() use myFunc. In javascript, a function with parens (and/or args) means you want to call it. A function name without them means you just want a reference to that function (which is probably what fancybox wants from you)

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