문제가 fancybox (버전 2.x) 닫기 버튼이 ID
을하지 않는다는 것입니다, 그것은 클래스 만, 그러나 당신이 [X]
버튼에 click
이벤트를 결합하고 당신의 상태를 설정할 수 있습니다 경우 [X]
닫기 버튼을 눌렀는지 여부.
의 currentTarget
이 click
이벤트와 같은 변수에 잡기보십시오 : 당신이 원하는 작업,
var eTarget;
jQuery(document).ready(function ($) {
$(".fancybox").fancybox({
afterShow: function() {
// bind a click event to fancybox close button
// set the value of the currentTarget to the eTarget variable
eTarget=""; // reset variable
$(".fancybox-close").on("click", function (event) {
eTarget = event.currentTarget;
});
},
afterClose: function() {
// validate the eTarget variable
if ($(eTarget).hasClass("fancybox-close")) {
// yes, we are closing fancybox with the [X] button
// so close it, do nothing and return
console.log("fancybox was closed using the X button");
return;
}
// only if fancybox wasn't close using the X button
// executed my validation and manual close
console.log("perform form submission and validation here")
}
});
}); // ready
JSFIDDLE
출처
2014-02-27 17:50:06
JFK
을' 클릭 한 요소의 'id'? 여기를 읽으면서, 당신이 필요로하는 것을위한 방법이 있습니다. http://fancybox.net/api – rockStar