【发布时间】:2014-12-03 02:06:12
【问题描述】:
我在 laravel 环境中使用 magnific popup 并希望两者一起工作,所以我写了这个:
Here's a fiddle with the problem
$(document).ready(function() {
$('.image-popup-vertical-fit').on('click',function(){
var image = $(this).attr('src');
popnow(image);
});
function popnow(a) {
$('.image-popup-vertical-fit').magnificPopup({
type: 'image',
closeOnContentClick: true,
mainClass: 'mfp-img-mobile',
image: {
verticalFit: true
},
items: {
src: a
}
});
}
});
HTML:
<div class="col-lg-6 col-sm-6 margin-top-60">
{{HTML::image('images/recentprojects1.png','recent',array('class' => 'img-responsive img-center image-popup-vertical-fit')) }}
</div>
<div class="col-lg-6 col-sm-6 margin-top-60" id="test">
{{ HTML::image('images/pricing1.png','recent',array('class' => 'img-responsive img-center image-popup-vertical-fit')) }}
</div>
如果我在页面重新加载后第一次单击弹出式打开图像,则没有任何反应,如果我第二次单击它会打开。
但是当我在页面重新加载后第一次点击第一个 div 之后我点击第二个时,它仍然向我显示第一个点击的 div 的内容(第一次点击第二个 div - 错误的图像)。
所以似乎每次点击都不需要var image。我的功能有问题吗?
当我将console.log(a) 添加到function popnow(a) 的顶部时,会记录正确的图像src。
【问题讨论】:
标签: javascript jquery