After spending a few hours, I could not figure out the best practise to use the 'client-side' functionality on EJS page. The scenario is stated below:
// Sticky bar
window.onscroll = function() {myFunction()};
var navbar = document.getElementById("navbar");
var sticky = navbar.offsetTop;
function myFunction() {
if (window.pageYOffset >= sticky) {
navbar.classList.add("sticky")
} else {
navbar.classList.remove("sticky");
}
}
When you use js files in ejs, it is like you don't use ejs or nodejs. It's just static files. And you can't use npm package.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.