Skip to content

Instantly share code, notes, and snippets.

@wuct
Last active August 29, 2015 14:21
Show Gist options
  • Save wuct/3e39f080613c34278591 to your computer and use it in GitHub Desktop.
Save wuct/3e39f080613c34278591 to your computer and use it in GitHub Desktop.
try to use raf in react
_animateIcon() {
const initTime = Date.now();
raf(function tick() {
const {icon} = this.state;
const diffTime = Date.now() - initTime;
const renderTime = diffTime % 4000;
const iconSize = (renderTime / 1000) * 10 + 10;
// console.log(iconSize);
icon.scaledSize = new google.maps.Size(iconSize, iconSize);
icon.anchor = new google.maps.Point(iconSize / 2, iconSize / 2);
this.setState({icon});
raf(tick.bind(this));
}.bind(this));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment