我與在laravel環境蕩氣迴腸彈出的工作,並希望雙方要共同努力,所以我寫了這個:函數打開彈出之前沒有第二次點擊
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。