我使用swup.js进行页面转换,并通过AJAX更改内容。不幸的是,重力表单似乎不能很好地处理AJAX请求,并且我的表单在转换后无法正常工作。
我使用以下代码在页面加载时重新初始化我的脚本:
document.addEventListener('swup:pageView', (event) => {
// code
})
有没有什么函数可以在javascript中重新初始化,以便在每次页面转换时重力式表单都会重新初始化?在文档中找不到任何内容。
发布于 2020-04-26 07:40:30
我知道这篇文章的发表日期很远,但是这个问题突然出现在我面前,如果你找不到答案的话,
尝试使用此代码,它将监视应用于body的DOM的任何更改,并将触发您想要的任何更改:
<script>
$(document).on('DOMSubtreeModified', 'body', function (el) {
console.log('body content changed');
// append you init code here
});
</script>
告诉我这有没有用。
发布于 2020-10-15 22:37:37
最终使用的是SwupFormsPlugin和Contact Form 7,其中包含以下内容
document.addEventListener('DOMContentLoaded', function (event) {
var domain = window.location.origin // HACK: makes link selector relative
var isMobile = window.innerWidth < 800
if (isMobile) {
} else {
var swup = new Swup({
plugins: [
new SwupOverlayTheme({
color: '#eff6fb',
duration: 3000,
direction: 'to-bottom',
}),
new SwupBodyClassPlugin(),
new SwupFormsPlugin({ formSelector: 'form.wpcf7-form' }),
new SwupScrollPlugin({
doScrollingRightAway: false,
animateScroll: true,
scrollFriction: 0.3,
scrollAcceleration: 0.04,
}),
],
FORM_SELECTOR: 'form.wpcf7-form',
LINK_SELECTOR: 'a[href*="'.concat(
domain,
'"]:not([data-no-swup]), a[href^="/"]:not([data-no-swup]), a[href^="#"]:not([data-no-swup]), a[xlink\\:href]'
),
})
swup()
}
})
function domReady (callback) {
document.readyState === 'interactive' || document.readyState === 'complete'
? callback()
: document.addEventListener('DOMContentLoaded', callback)
}
export { domReady }
家,它帮助任何人
https://stackoverflow.com/questions/60542351
复制相似问题