Skip to content

Commit

Permalink
refactor: implement animation with margin
Browse files Browse the repository at this point in the history
  • Loading branch information
benjycui committed Dec 6, 2016
1 parent 6b895e1 commit 13d4095
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion assets/index/common.less
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@
}

&-animated {
transition: transform @effect-duration @easing-in-out;
transition: transform @effect-duration @easing-in-out,
margin-left @effect-duration @easing-in-out,
margin-top @effect-duration @easing-in-out;
display: flex;
will-change: transform;

Expand Down
5 changes: 2 additions & 3 deletions src/TabContent.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, { PropTypes } from 'react';
import classnames from 'classnames';
import {
getTransformByIndex,
getActiveIndex,
getTransformPropValue,
getMarginStyle,
} from './utils';

const TabContent = React.createClass({
Expand Down Expand Up @@ -59,7 +58,7 @@ const TabContent = React.createClass({
if (activeIndex !== -1) {
style = {
...style,
...getTransformPropValue(getTransformByIndex(activeIndex, tabBarPosition)),
...getMarginStyle(activeIndex, tabBarPosition),
};
} else {
style = {
Expand Down
8 changes: 8 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,11 @@ export function getTransformByIndex(index, tabBarPosition) {
const translate = isVertical(tabBarPosition) ? 'translateY' : 'translateX';
return `${translate}(${-index * 100}%) translateZ(0)`;
}

export function getMarginStyle(index, tabBarPosition) {
const marginDirection = isVertical(tabBarPosition) ? 'marginTop' : 'marginLeft';
return {
[marginDirection]: `${-index * 100}%`,
width: '100%',
};
}

0 comments on commit 13d4095

Please sign in to comment.