小于 1 分钟
class Yy{
constructor(arg){
if (typeof selector == "object") {
this.el = [selector]
} else {
this.el = document.querySelectorAll(arg);
}
}
color(val) {
console.log(this.el)
for (let i = 0; i < this.el.length; i++) {
console.log(this.el[i])
this.el[i].style.color = val;
}
return this;
}
css = function (option, value) {
if (value === undefined) {
for (let i = 0; i < this.el.length; i++) {
for (const key in option) {
this.el[i].style[key] = option[key];
}
}
} else {
for (let i = 0; i < this.el.length; i++) {
this.el[i].style[option] = value;
}
}
return this;
}
addClass = function (...option) {
for (let i = 0; i < this.el.length; i++) {
for (const value of option) {
this.el[i].classList.add(value);
}
}
return this;
}
toggleClass = function (...option) {
for (let i = 0; i < this.el.length; i++) {
for (const value of option) {
this.el[i].classList.toggle(value)
}
}
return this;
}
on = function (method, fn) {
for (let i = 0; i < this.el.length; i++) {
this.el[i].fn = fn;
this.el[i].addEventListener(method, function (e) {
this.fn(e);
})
}
}
attr = function (key, value) {
for (let i = 0; i < this.el.length; i++) {
if (value == undefined) {
return this.el[i].getAttribute(key)
}else{
return this.el[i].setAttribute(key,value)
}
}
}
}
function instance(arg){
return new Yy(arg)
}
let $ = instance;
export default $;