41 lines
1.0 KiB
JavaScript
41 lines
1.0 KiB
JavaScript
/*
|
|
* @Author: ddmt
|
|
* @Date: 2024-9-29 20:50:12
|
|
* @LastEditTime: 2024-9-30 0:12:12
|
|
* @LastEditors: ddmt
|
|
* @Description: ddmt-index file
|
|
* @FilePath: /Tool/animate.js
|
|
*/
|
|
|
|
/**
|
|
* 动画函数
|
|
* @param {HTMLElement} HTMLElement
|
|
* @param {string} classname
|
|
* @param {boolean} forceExecute
|
|
* @returns {void}
|
|
*/
|
|
export function animateStart(HTMLElement, className, forceExecute=false) {
|
|
if (forceExecute) HTMLElement.target.classList.remove(className); // 清洗动画
|
|
HTMLElement.classList.add(className);
|
|
HTMLElement.addEventListener('animationend', (event) => {
|
|
event.target.classList.remove(className); // 清洗动画
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 设置CSS变量值
|
|
* @param {string} varName
|
|
* @param {string} value
|
|
*/
|
|
export function setClassVar(varName, value) {
|
|
document.documentElement.style.setProperty(varName, value);
|
|
}
|
|
|
|
/**
|
|
* 获取CSS变量值
|
|
* @param {string} varName
|
|
* @returns
|
|
*/
|
|
export function getStyleVar(varName) {
|
|
return getComputedStyle(document.documentElement).getPropertyValue(varName);
|
|
} |