$('body').scrollspy({
target: '#nav',
offset: $(window).height() / 2
});
報錯:
Uncaught TypeError: $(…).scrollSpy is not a function
首先檢查自己引入jquery是不是在其他js語句之前。
其次想要使用scrollspy().必須提前 import bootstrap.min.js .
<script type="text/javascript" src="static/js/bootstrap.min.js"></script>
官網:https://getbootstrap.com/docs/4.0/components/scrollspy/