如果在模态内不起作用
If doesn't work inside a modal
如果 HTML 在 DOM 内,它工作正常。但是我有一个 AJAX-modal(很棒的弹出窗口),脚本在那里不起作用。
class "no-touch" 不会被删除,有什么想法我必须改变它也可以在模态中工作吗?
$(document).ready(function() {
win_w = $(window).width();
win_h = $(window).height();
if (/Mobi/i.test(navigator.userAgent)) {
$(".mgu-profil-selection__food5, .mgu-profil-selection__food6").removeClass("no-touch");
}
})
您的代码仅在页面加载时执行,您还应该 运行 在 ajax 请求之后
您可以将回调分配给您的精彩弹出窗口(参见 docs)
function check() {
win_w = $(window).width();
win_h = $(window).height();
if (/Mobi/i.test(navigator.userAgent)) {
$(".mgu-profil-selection__food5, .mgu-profil-selection__food6").removeClass("no-touch");
}
}
$(document).ready(function() {
check();
})
$('.image-link').magnificPopup({
type: 'image',
callbacks: {
ajaxContentAdded: function() {
// Ajax content is loaded and appended to DOM
// run check function again
check();
}
}
});
如果 HTML 在 DOM 内,它工作正常。但是我有一个 AJAX-modal(很棒的弹出窗口),脚本在那里不起作用。
class "no-touch" 不会被删除,有什么想法我必须改变它也可以在模态中工作吗?
$(document).ready(function() {
win_w = $(window).width();
win_h = $(window).height();
if (/Mobi/i.test(navigator.userAgent)) {
$(".mgu-profil-selection__food5, .mgu-profil-selection__food6").removeClass("no-touch");
}
})
您的代码仅在页面加载时执行,您还应该 运行 在 ajax 请求之后
您可以将回调分配给您的精彩弹出窗口(参见 docs)
function check() {
win_w = $(window).width();
win_h = $(window).height();
if (/Mobi/i.test(navigator.userAgent)) {
$(".mgu-profil-selection__food5, .mgu-profil-selection__food6").removeClass("no-touch");
}
}
$(document).ready(function() {
check();
})
$('.image-link').magnificPopup({
type: 'image',
callbacks: {
ajaxContentAdded: function() {
// Ajax content is loaded and appended to DOM
// run check function again
check();
}
}
});