我的页面内容是动态的 <?php the_content(); ?>
,并且我无法定义图像的 a
带有 html 的类。所以,我用javascript添加了:$('.single-post img').parent('a').addClass("image-popup-no-margins");
虽然一切都正常加载,但这不起作用。有人知道为什么吗?
这是 fiddle :http://jsfiddle.net/casslt07/jujpewz9/
最佳答案
将 addClass 代码移到设置放大弹出窗口的代码之前,它应该可以工作。
$(document).ready(function() {
$('img').parent('a').addClass("image-popup-no-margins");
$('.image-popup-no-margins').magnificPopup({
type: 'image',
closeOnContentClick: true,
closeBtnInside: false,
fixedContentPos: true,
mainClass: 'mfp-no-margins mfp-with-zoom', // class to remove default margin from left and right side
image: {
verticalFit: true
},
zoom: {
enabled: true,
duration: 300 // don't foget to change the duration also in CSS
}
});
});
关于javascript - 带 WordPress 图像的华丽弹出窗口(php 内容),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32577954/