Files
ClassContent/历届学生/韩一伟/项目开发/上课项目/美食App/js/util/index.js
2024-09-27 02:06:13 +08:00

53 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class Util {
//节流throttle代码:
throttle(fn,delay) {
let canRun = true; // 通过闭包保存一个标记
return function () {
if (!canRun) return;
canRun = false;
setTimeout(() => {
fn.apply(this, arguments);
canRun = true;
}, delay);
};
}
footer () {
var body = $("body")
var currentPath = location.href.split("page/")[1];
var html = `
<ul class="footer clear">
${
config.footer.map((v,i) => {
var isCurrent = v.path.includes(currentPath);
return `
<li class="${ isCurrent ? 'footer_active' : '' }">
<a href="${v.path}">
<img src="${isCurrent ? `../img/${v.icon}1.png` : `../img/${v.icon}.png`}">
<span>${v.title}</span>
</a>
</li>
`
}).toString().replaceAll(",","")
}
</ul>
`
body.append(html)
}
query(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]);
return null;
}
}
var {footer, query, throttle} = new Util();