mirror of
https://github.com/element-plus/element-plus.git
synced 2024-12-27 03:01:14 +08:00
f12000f9c2
* feat: add website * chore: fix
23 lines
553 B
JavaScript
23 lines
553 B
JavaScript
export const hasClass = function(obj, cls) {
|
|
return obj.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'))
|
|
}
|
|
|
|
export const addClass = function(obj, cls) {
|
|
if (!hasClass(obj, cls)) obj.className += ' ' + cls
|
|
}
|
|
|
|
export const removeClass = function(obj, cls) {
|
|
if (hasClass(obj, cls)) {
|
|
const reg = new RegExp('(\\s|^)' + cls + '(\\s|$)')
|
|
obj.className = obj.className.replace(reg, ' ')
|
|
}
|
|
}
|
|
|
|
export const toggleClass = function(obj, cls) {
|
|
if (hasClass(obj, cls)) {
|
|
removeClass(obj, cls)
|
|
} else {
|
|
addClass(obj, cls)
|
|
}
|
|
}
|