Skip to content

Commit

Permalink
feat: divide cssTransform into cssTransform & stopCssTransform
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Nov 13, 2018
1 parent f36ffd8 commit 197d44b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
32 changes: 11 additions & 21 deletions src/cssTransform.ts
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
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export { default as sample } from './sample'
export { default as set } from './set'
export { default as shuffle } from './shuffle'
export { default as startsWith } from './startsWith'
export { default as stopCssTransform } from './stopCssTransform'
export { default as stopEventPropagation } from './stopEventPropagation'
export { default as storage } from './storage'
export { default as supportPassiveEventListener } from './supportPassiveEventListener'
Expand Down
13 changes: 13 additions & 0 deletions src/stopCssTransform.ts
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'
}
7 changes: 2 additions & 5 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@ describe('base64', () => {
})
test('decode', () => {
data.forEach(([str, encodedStr]) => {
if (str === 'v') {
console.log(str, vtils.base64Decode(encodedStr).length, String(str).length)
}
expect(vtils.base64Decode(encodedStr)).toBe(String(str))
})
})
Expand Down Expand Up @@ -541,8 +538,8 @@ describe('cssTransform', () => {
expect(el.style.transform).toBe('translateX(100px)')
expect(el.style.transition).toBe('transform .3s ease')
})
test('cssTransform.stop', () => {
vtils.cssTransform.stop(el)
test('stopCssTransform', () => {
vtils.stopCssTransform(el)
expect(el.style.transition).toBe('none')
})
})
Expand Down

0 comments on commit 197d44b

Please sign in to comment.