带有Backbone的Magnific弹出窗口仅在第二次单击后触发

时间:2014-04-28 17:50:11

标签: jquery backbone.js magnific-popup

我遇到的问题与此jquery click on href link - have to click twice非常相似。第一次单击后,图像弹出窗口正常工作

  

因为看起来插件负责绑定点击处理程序   为你,这意味着你的第一次点击绑定弹出窗口   功能(包括onclick处理程序)所以它只能工作   再次点击。

我使用带有require.js的Backbone 1.0.0。

我的代码如下:

骨干视图

events:{
'click .test-popup-link':'popImg',
}

popImg: function (e) {
      e.preventDefault();
      $('.test-popup-link').magnificPopup({
        delegate: 'a',
        type: 'image',
        //closeBtnInside: false,
        closeOnContentClick: true,
        overflowY: 'auto',
        mainClass: 'mfp-img-mobile',
        image: {
          verticalFit: true
        }
      });

    },

HTML

   <div class='test-popup-link'><a class='image-popup-vertical-fit'        href="http://mydomain.com/files/8e0183d4179a11e2880f22000a1e8aaf_7%20(15).jpg"><img id='6576465avt7a6768'       src="http://mydomain.com/files/8e0183d4179a11e2880f22000a1e8aaf_7%20(15).jpg"></a></div>;

任何帮助非常感谢。感谢。

1 个答案:

答案 0 :(得分:0)

你可以在你的initialize函数中执行此操作:

SearchView = Backbone.View.extend({
    el: $(".open-popup-link"),
    initialize: function () {
        $(this.el).magnificPopup({
            type: 'inline',
            midClick: true
        });
    }
});
var search_view = new SearchView();

请参阅演示:http://jsfiddle.net/Cardiff/UWXNd/

相关问题