作为业余爱好者,我正在开发一个wordpress网站。
我已将脚本直接放在<head>
下面。我希望它在正确入队之前先工作。
<script>
jQuery(document).ready(function(){
jQuery('#cta-section').waypoint(function() {
jQuery('#cta-section').toggleClass('animate-cta');
}, {offset: '80%'});
});
</script>
我一直收到以下错误:
(index):13 Uncaught TypeError: jQuery(...).waypoint is not a function
at HTMLDocument.<anonymous> ((index):13)
at j (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at Function.ready (jquery.min.js:2)
at HTMLDocument.I (jquery.min.js:2)
(index):963 Uncaught TypeError: jQuery(...).waypoint is not a function
at HTMLDocument.<anonymous> ((index):963)
at i (jquery.js?ver=1.12.4:2)
at Object.fireWith [as resolveWith] (jquery.js?ver=1.12.4:2)
at Function.ready (jquery.js?ver=1.12.4:2)
at HTMLDocument.K (jquery.js?ver=1.12.4:2)
答案 0 :(得分:0)
我找到了解决方案。唯一令人讨厌的一点是,我需要使用ShrinkOn
数字。
<< / p>
script>
function resizeCTAOnScroll() {
const distanceY = window.pageYOffset || document.documentElement.scrollTop,
shrinkOn = 1850,
headerEl = document.getElementById('cta-section');
if (distanceY > shrinkOn) {
headerEl.classList.add("animate-cta");
} else {
headerEl.classList.remove("animate-cta");
}
}
window.addEventListener('scroll', resizeCTAOnScroll);
</script>