문제

I have an element that loads from AJAX. With tthat element, I attached Facebox.js. When the element is clicked, it will triggered Facebox. So I used:

$(document).on("click", "a[rel*=modal]", function() {
    $(this).facebox(); // Applies modal window to any link with attribute rel="modal"
});

The thing is, it requires the element to be clicked twice before Facebox is triggered. So as a quick fix, I added:

$('a[rel*=modal]').trigger('click');

This way, I can click the element only once to trigger. Is there a better way to fix ?

도움이 되었습니까?

해결책

The problem is when the first click happens the facebox plugin is not initialized, a workaround is to initialize the plugin and then re-trigger the click event again

$(document).one("click", "a[rel*=modal]", function() {
    $(this).facebox().triggerHandler('click');
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top