-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: divide cssTransform into cssTransform & stopCssTransform
- Loading branch information
Showing
4 changed files
with
27 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,20 @@ | ||
interface CssTransform { | ||
(el: HTMLElement, transformRule: string, transitionRule: string): void, | ||
/** | ||
* 停止 CSS 变换。 | ||
* | ||
* @param el 要停止变换的元素 | ||
*/ | ||
stop(el: HTMLElement): void | ||
} | ||
|
||
/** | ||
* CSS 变换。 | ||
* | ||
* @param el 要变换的元素 | ||
* @param transformRule 变换规则 | ||
* @param transitionRule 过渡规则 | ||
*/ | ||
const cssTransform: CssTransform = (el: HTMLElement, transformRule: string, transitionRule: string): void => { | ||
el.style.webkitTransform = transformRule | ||
el.style.transform = transformRule | ||
el.style.webkitTransition = `-webkit-transform ${transitionRule}` | ||
export default function cssTransform(el: HTMLElement, transformRule: string, transitionRule: string): void { | ||
el.style.transform | ||
= (el.style as any).msTransform | ||
= (el.style as any).OTransform | ||
= (el.style as any).MozTransform | ||
= (el.style as any).webkitTransform | ||
= transformRule; | ||
(el.style as any).webkitTransition = `-webkit-transform ${transitionRule}`; | ||
(el.style as any).mozTransition = `-moz-transform ${transitionRule}`; | ||
(el.style as any).oTransition = `-o-transform ${transitionRule}`; | ||
(el.style as any).msTransition = `-ms-transform ${transitionRule}` | ||
el.style.transition = `transform ${transitionRule}` | ||
} | ||
|
||
cssTransform.stop = (el: HTMLElement): void => { | ||
el.style.webkitTransition = 'none' | ||
el.style.transition = 'none' | ||
} | ||
|
||
export default cssTransform |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* 停止 CSS 变换。 | ||
* | ||
* @param el 要停止变换的元素 | ||
*/ | ||
export default function stopCssTransform(el: HTMLElement): void { | ||
el.style.transition | ||
= (el.style as any).msTransition | ||
= (el.style as any).oTransition | ||
= (el.style as any).mozTransition | ||
= (el.style as any).webkitTransition | ||
= 'none' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters