Skip to content

Instantly share code, notes, and snippets.

@lazyTai
Created September 28, 2017 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lazyTai/d6a95e49ad3407f552368729198ed1dd to your computer and use it in GitHub Desktop.
Save lazyTai/d6a95e49ad3407f552368729198ed1dd to your computer and use it in GitHub Desktop.
reboundjs
import React from 'react'
import rebound from 'rebound'
var springSystem = new rebound.SpringSystem();
var spring = springSystem.createSpring(50, 3);/* 50---3 */
function setSpring(el) {
spring.addListener({
onSpringUpdate: function (spring) {
var val = spring.getCurrentValue();
val = rebound.MathUtil
.mapValueInRange(val, 0, 1, 1, 0.5);
scale(el, val);
}
});
function scale(el, val) {
el.style.mozTransform =
el.style.msTransform =
el.style.webkitTransform =
el.style.transform = 'scale3d(' +
val + ', ' + val + ', 1)';
}
}
class App extends React.Component {
componentDidMount() {
var box = this.refs['wrapper'];
setSpring(box)
box.addEventListener('mousedown', function () {
spring.setEndValue(1);
})
box.addEventListener('mouseup', function () {
spring.setEndValue(0);
});
}
render() {
return <div ref="wrapper"
style={{
width: 100,
height: 100
}}
>
helloarebound.jsx
</div>
}
}
export default App
import React from 'react'
import rebound from 'rebound'
var springSystem = new rebound.SpringSystem();
var spring = springSystem.createSpring(50, 3);/* 50---3 */
function setSpring(el) {
spring.addListener({
onSpringUpdate: function (spring) {
var val = spring.getCurrentValue();
val = rebound.MathUtil
.mapValueInRange(val, 0, 1, 1, 0.5);
scale(el, val);
}
});
function scale(el, val) {
el.style.mozTransform =
el.style.msTransform =
el.style.webkitTransform =
el.style.transform = 'scale3d(' +
val + ', ' + val + ', 1)';
}
}
class App extends React.Component {
componentDidMount() {
var box = this.refs['wrapper'];
setSpring(box)
box.addEventListener('mousedown', function () {
spring.setEndValue(1);
})
box.addEventListener('mouseup', function () {
spring.setEndValue(0);
});
}
render() {
return <div ref="wrapper"
style={{
width: 100,
height: 100
}}
>
helloarebound.jsx
</div>
}
}
export default App
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment