53 lines
1.7 KiB
JavaScript
53 lines
1.7 KiB
JavaScript
function $(className) {
|
|
var newClassName = className.split(" ");
|
|
if (newClassName.length > 1) {
|
|
var father = newClassName[newClassName.length - 2];
|
|
var childrenList = document.querySelector(father).children;
|
|
|
|
var arr = Array.from(childrenList).filter(function (el) {
|
|
if (
|
|
el.className.indexOf((newClassName[newClassName.length - 1]).replace(".", "")) > -1
|
|
||
|
|
el.tagName.toLowerCase() == newClassName[newClassName.length - 1]
|
|
) {
|
|
return el;
|
|
}
|
|
});
|
|
|
|
if (arr.length > 1) {
|
|
return document.querySelectorAll(className)
|
|
} else if (arr.length == 1) {
|
|
return document.querySelector(className)
|
|
} else {
|
|
throw new Error(`${className} 不存在,请检查`)
|
|
}
|
|
|
|
} else {
|
|
return document.querySelector(newClassName);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
// function scroll(callback) {
|
|
// document.querySelector('bode').onscroll = () => {
|
|
// let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
|
|
// let clientHeight = document.documentElement.clientHeight || document.body.clientHeight;
|
|
// let scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
|
|
|
|
// if (scrollHeight > clientHeight && scrollTop + clientHeight === scrollHeight) {
|
|
// Array.from(b).filter((v, i) => {
|
|
// if (v.className.indexOf("active") > -1) {
|
|
// this.currentIndex = i;
|
|
// }
|
|
// });
|
|
|
|
// this.allUserDo[this.currentIndex].page += 1;
|
|
// this.getdata("scroll");
|
|
// console.log(this.currentIndex)
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
|