【发布时间】:2015-12-06 06:40:01
【问题描述】:
我认为这将是一个非常简单的问题:如何覆盖 Magnific Popup 的默认加载方法:我不想在单击时加载图像,而是在双击时加载。
我正在使用该模块在网站上加载图像。这是页面的js代码:
$(document).ready(function() {
// override magnificPopup.resizeImage:
$.magnificPopup.instance.resizeImage = betterResizeImage;
var magnific = $('#photoList').magnificPopup({
delegate: 'img', // child items selector, by clicking on it popup will open
type: 'image',
closeOnContentClick: true,
});
$.getJSON('/json', function(json) {
console.log('got json');
json.forEach(function(item) {
var img=$('<img/>')
.attr('src', '/img/' + item.thumbnail)
.attr('class', 'thumnail')
.attr('data-mfp-src', '/img/' + item.file_name)
.on('load', function() {
if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) {
console.log('error loading ' + item.thumbnail);
} else {
$('#photoList').append(img);
}
});
});
});
});
$('#photoList') 只是一个 div,其中包含在页面加载后附加到它的图像。我想要做的就是将单击事件释放为其他内容,而是在双击时打开 Magnific Popup。
我不知道在模块代码中的哪个位置注册了 onclick 事件以打开模块,以及我将如何覆盖它。 Mosh Feu 的回答很接近,但每次双击任何图像时都会打开 div 中的第一张图像。
Github 上的精彩弹出窗口: https://github.com/dimsemenov/Magnific-Popup
【问题讨论】:
-
您的用户会理解这种对已建立的用户界面交互的更改吗?
-
PS:在 fastclick 插件中点击处理程序被覆盖
-
添加代码会更好。人们将能够编辑您的代码并快速提供解决方案
标签: javascript jquery html popup magnific-popup