在另一个完成后运行JQuery函数

时间:2016-04-05 18:25:16

标签: jquery callback fancybox synchronous owl-carousel-2

我有两个JQuery函数用于显示Fancybox,第二个用于创建owl-carousel,我希望awl carousel函数在fancybox函数运行后运行。

$(document).ready(function() {
    $(".fancybox1").fancybox({
        content : '<div  class="col-md-6"><div id="fancybox12" class="owl-carousel owl-theme"><div class="item"><img src="img/portfolio/102.jpg" class="img-responsive" alt="..."></div></div></div><div class="text-center col-md-6"><h1> T-Shirts & Fabric Printing </h1></div> '
   }),
   $("#fancybox12").owlCarousel({
          navigation : false, // Show next and prev buttons
          slideSpeed : 300,
          paginationSpeed : 400,
          singleItem:true
     });
});

但是我无法接听回电。请帮助我。 谢谢

1 个答案:

答案 0 :(得分:0)

尝试将它们放在一个单独的函数中,然后像这样调用该函数:

(document).ready(function() {
    runfancybox();

    function runfancybox(){
    $(".fancybox1").fancybox({
            content : '<div  class="col-md-6"><div id="fancybox12" class="owl-carousel owl-theme"><div class="item"><img src="img/portfolio/102.jpg" class="img-responsive" alt="..."></div></div></div><div class="text-center col-md-6"><h1> T-Shirts & Fabric Printing </h1></div> '
      });
      runOwlCarousel();
    }


    function runOwlCarousel(){
        $("#fancybox12").owlCarousel({
          navigation : false, // Show next and prev buttons
          slideSpeed : 300,
          paginationSpeed : 400,
          singleItem:true
          });     
    }
 });
相关问题