Fancybox v2 not working with Durandal

2019-09-10 02:06发布

问题:

I am not able to get Fancybox work with Durandal. I am using John Papa's Hot Towel Template as my starting point.

Problem: Whenever I click on the image it is navigating to the image path rather than overlaying it on top of the page.

Libraries: Jquery v 1.9.1 & FancyBox 2.1.4.

View:

<section>
    <a class="fancybox" title="Our fresh starters"     href="http://www.preschools4all.com/image-files/little-bunny-foo-foo-1.jpg">
        <img src="http://www.preschools4all.com/image-files/little-bunny-foo-foo-1.jpg"     alt="Our fresh starters" />
    </a>
</section>

ViewModel:

define(['services/logger', 'services/dataservice'], function (logger, dataservice) {

   var vm = {
        viewAttached: viewAttached,
        activate: activate,
    };

    return vm;

    function activate() {
           //Do something
          // return promise
    }

    function viewAttached() {            
        $(".fancybox").fancybox();
    }

});

BundleConfig:

bundles.Add(
 new ScriptBundle("~/scripts/vendor")
 .Include("~/scripts/jquery-{version}.js")
 .Include("~/scripts/jquery.fancybox.js")
 .Include("~/scripts/bootstrap.js")
);


bundles.Add(
 new StyleBundle("~/Content/css")
 .Include("~/Content/ie10mobile.css")
 .Include("~/Content/bootstrap.css")
 .Include("~/Content/jquery.fancybox.css")
);

What's wrong?

回答1:

It seemed like the problem was with bootstrap.js v 2.3.0

Boostrap 2.3.0 is incompatible with fancybox v2. I upgraded to use bootstrap 2.3.1 and solved my issue.