Skip to content

Instantly share code, notes, and snippets.

@cdata
Created May 13, 2014 14:13
Show Gist options
  • Select an option

  • Save cdata/625608c3d9a1c2082140 to your computer and use it in GitHub Desktop.

Select an option

Save cdata/625608c3d9a1c2082140 to your computer and use it in GitHub Desktop.
li {
display: block;
position: relative;
}
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<script src="http://julian.com/research/velocity/build/jquery.velocity.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/react/0.10.0/react-with-addons.js"></script>
</body>
</html>
var Item = React.createClass({
componentWillEnter: function (cb) {
$(this.getDOMNode()).css({ left: '10px', opacity: 0 }).velocity({ left: 0, opacity: 1 }, 'easeInOutQuad', cb);
},
componentWillLeave: function (cb) {
$(this.getDOMNode()).velocity({ left: '10px', opacity: 0 }, 'easeInOutQuint', cb);
},
render: function () {
return React.DOM.li({}, this.props.content + ' mod ' + Math.random());
}
});
var App = React.createClass({
getInitialState: function () {
return { items: 5 };
},
componentDidMount: function () {
var that = this;
window.setInterval(function () {
that.setState({ items: Math.floor(Math.random() * 100) });
}, 50);
},
render: function () {
var items = [];
for (var i = 0; i < this.state.items; ++i) {
items.push(Item({ content: 'Item ' + i }, null));
}
return React.addons.TransitionGroup({
transitionName: 'foo',
component: React.DOM.ul
}, items);
}
});
React.renderComponent(App(), document.body);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment