[英]How to use client side functionality on EJS page
After spending a few hours, I could not figure out the best practise to use the 'client-side' functionality on EJS page.花了几个小时后,我想不出在 EJS 页面上使用“客户端”功能的最佳实践。 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.当你在 ejs 中使用 js 文件时,就像你不使用 ejs 或 nodejs。 It's just static files.
这只是 static 文件。 And you can't use npm package.
而且你不能使用 npm package。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.