This commit is contained in:
hufeixiong
2022-03-29 18:02:59 +08:00
parent a1d6c398b6
commit 3495aa7956
3 changed files with 262 additions and 149 deletions

View File

@@ -0,0 +1,42 @@
// 批量情况
export class DynamicAnimate {
getStyleSheets() {
return document.styleSheets;
}
inserKeyframeAnimate(ruleText: string, keyframeName: string) {
const sheets = this.getStyleSheets();
if (sheets.length === 0) {
let style = document.createElement('style');
style.appendChild(document.createTextNode(''));
document.head.appendChild(style);
}
const len = sheets.length;
let ss: number | null = null;
let st: number | null = null;
for (let i = 0; i < len; i++) {
for (let k = 0; k < sheets[i].cssRules.length; k++) {
const rule = sheets[i].cssRules[k] as CSSKeyframesRule;
const name = rule?.name;
if (name && name === keyframeName) {
// 删除该keyframe
ss = i;
st = k;
}
}
}
if (ss !== null && st !== null) {
sheets[ss].deleteRule(st);
}
let sheet = sheets[ss ? ss : sheets.length - 1] as CSSStyleSheet;
sheet.insertRule(ruleText, sheet.rules ? sheet.rules.length : sheet.cssRules.length);
}
fromObjInsertKeyFrame(obj: Record<string, string>) {
// name 唯一
Object.keys(obj).forEach((v) => {
this.inserKeyframeAnimate(obj[v], v);
});
}
}

View File

@@ -27,6 +27,7 @@ export interface AnimateItem {
animationIterationCount: string;
animationTimingFunction: string;
isCustom?: boolean;
customKeyFrame?: string;
}
export interface IBlockType {