content logo

React Buttons:

Circular Download Button with Size Changing Effect using React

To download a file from your website, you can use animation to make the user feel the download process better and more attractive to the user of your website. As you can see in this code, a circular button is located in the middle of the page. There is also a download icon button. The button itself is white and its background is normally blue, and by clicking on the button, first the button icon turns into a counter that goes up to 100, and finally the background turns green and the button icon changes to a success sign.

#

Animating Download Button

#

Circular Download Button Code

#

Javascript Animating Button

#

Dynamic Size Button Example

<!-- This script got from frontendfreecode.com -->
<div id="page"></div><a style="font-size: 8pt; text-decoration: none" target="_blank" href="http://frontendfreecode.com">Free Frontend</a>
                                                                            
@import url(https://fonts.googleapis.com/css?family=Roboto:400,100,100italic,300,300italic,400italic,500,500italic,700,700italic,900,900italic&subset=latin,greek);
@import url(https://fonts.googleapis.com/css?family=Roboto+Mono:400,100,100italic,300,300italic,400italic,500,500italic,700,700italic);
html,
body {
  margin: 0;
  padding: 0;
}
body {
  font-family: 'Roboto', sans-serif;
  font-size: 100%;
  color: #1f2e3e;
  position: absolute;
  width: 100%;
  height: 100%;
}
#page {
  position: relative;
  width: 100%;
  height: 100%;
  display: -webkit-flex;
  display: flex;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-align-items: center;
  align-items: center;
  background-color: #2196f3;
}
#page.orange {
  background-color: #ff5722;
}
#page .material_button {
  position: relative;
  cursor: pointer;
  width: 64px;
  height: 64px;
  line-height: 64px;
  text-align: center;
}
#page .material_button:before {
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  content: "";
  -moz-border-radius: 50%;
  -webkit-border-radius: 50%;
  border-radius: 50%;
  position: absolute;
  -moz-box-shadow: 0 5px 11px 0 rgba(0, 0, 0, 0.18), 0 4px 15px 0 rgba(0, 0, 0, 0.15);
  -webkit-box-shadow: 0 5px 11px 0 rgba(0, 0, 0, 0.18), 0 4px 15px 0 rgba(0, 0, 0, 0.15);
  box-shadow: 0 5px 11px 0 rgba(0, 0, 0, 0.18), 0 4px 15px 0 rgba(0, 0, 0, 0.15);
  opacity: 0;
  -moz-transition: opacity 0.25s ease-out;
  -o-transition: opacity 0.25s ease-out;
  -webkit-transition: opacity 0.25s ease-out;
  transition: opacity 0.25s ease-out;
}
#page .material_button:hover:before {
  opacity: 1;
}
#page .material_button i {
  position: relative;
  height: 64px;
  width: 64px;
  line-height: 64px;
  position: relative;
  z-index: 99;
}
#page .material_button i.done {
  opacity: 0;
  visibility: hidden;
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
}
#page .material_button svg {
  position: absolute;
  top: 50%;
  left: 50%;
  -moz-transform: translate3d(-50%, -50%, 0);
  -ms-transform: translate3d(-50%, -50%, 0);
  -webkit-transform: translate3d(-50%, -50%, 0);
  transform: translate3d(-50%, -50%, 0);
  z-index: 0;
  overflow: visible;
}
#page .material_button svg circle {
  fill: #fff;
}
#page .material_button svg circle#green_ripple {
  fill: #8bc34a;
}
#page .material_button .progress {
  font-family: 'Roboto Mono', sans-serif;
  opacity: 0;
  visibility: hidden;
  position: absolute;
  width: 100%;
  height: 100%;
  text-align: center;
  z-index: 9;
}
footer {
  position: absolute;
  width: 100%;
  left: 0;
  bottom: 0;
  text-align: center;
  padding: 16px 0;
  color: #FFFFFF;
  font-size: 14px;
}
footer a {
  color: #1e59af;
}
function wndsize() {
  var w = 0;
  var h = 0;
  //IE
  if (!window.innerWidth) {
    if (!(document.documentElement.clientWidth == 0)) {
      //strict mode
      w = document.documentElement.clientWidth;
      h = document.documentElement.clientHeight;
    } else {
      //quirks mode
      w = document.body.clientWidth;
      h = document.body.clientHeight;
    }
  } else {
    //w3c
    w = window.innerWidth;
    h = window.innerHeight;
  }
  return {
    width: w,
    height: h };
}
// map function
Number.prototype.map = function (in_min, in_max, out_min, out_max) {
  return (this - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
};
var doc = document,
page = doc.getElementById('page'),
timeAnim = 1.25;
var Ripple = React.createClass({ displayName: "Ripple",
  getInitialState: function () {
    return {
      x: "",
      y: "",
      w: wndsize().width,
      h: wndsize().height };
  },
  rippleAnim: function (event) {
    var dom = this.refs.ripple.getDOMNode(),
    greenDom = this.refs.greenripple.getDOMNode(),
    tl = new TimelineMax(),
    offsetX = Math.abs(this.state.w / 2 - event.pageX),
    offsetY = Math.abs(this.state.h / 2 - event.pageY),
    deltaX = this.state.w / 2 + offsetX,
    deltaY = this.state.h / 2 + offsetY,
    scale_ratio = Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2));
    TweenMax.set([dom, greenDom], { transformOrigin: "center center" });
    tl.
    to(dom, timeAnim, {
      attr: {
        r: scale_ratio },
      ease: Power3.easeOut,
      onComplete: function () {
        classie.add(page, "orange");
      } }).
    to(dom, 2 * timeAnim, {
      attr: {
        r: 32 },
      delay: timeAnim / 3,
      ease: Power0.easeNone }).
    to(greenDom, timeAnim / 2, {
      attr: {
        r: scale_ratio },
      delay: timeAnim / 3,
      ease: Power3.easeOut });
  },
  componentWillReceiveProps: function (nextProps) {
    if (nextProps.activity === "play") {
      switch (nextProps.point) {
        case "one":
          this.setState({
            x: nextProps.event.pageX,
            y: nextProps.event.pageY });
          this.rippleAnim(nextProps.event);
          break;
        case "two":
          var dom = this.refs.ripple.getDOMNode(),
          greenDom = this.refs.greenripple.getDOMNode(),
          tl = new TimelineMax(),
          offsetX = Math.abs(this.state.w / 2 - this.state.x),
          offsetY = Math.abs(this.state.h / 2 - this.state.y),
          deltaX = this.state.w / 2 + offsetX,
          deltaY = this.state.h / 2 + offsetY,
          scale_ratio = Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2));
          tl.
          to(dom, timeAnim, {
            attr: {
              r: scale_ratio },
            onComplete: function () {
              classie.remove(page, "orange");
              TweenMax.set(greenDom, {
                attr: {
                  r: 32 } });
            },
            ease: Power3.easeOut }).
          to(dom, timeAnim / 2, {
            attr: {
              r: 32 },
            ease: Power3.easeOut });
          break;}
    }
  },
  render: function () {
    return /*#__PURE__*/(
      React.createElement("svg", { height: "1", width: "1" }, /*#__PURE__*/
      React.createElement("circle", { ref: "greenripple", id: "green_ripple", cx: "0", cy: "0", r: "32" }), /*#__PURE__*/
      React.createElement("circle", { ref: "ripple", id: "white_ripple", cx: "0", cy: "0", r: "32" })));
  } });
var Button = React.createClass({ displayName: "Button",
  handleClick: function (e) {
    var self = this;
    if (this.state.action === "paused") {
      this.setState({
        action: "play",
        point: "one",
        progress: 0,
        event: e.nativeEvent });
      var arrow = this.refs.arrow_icon.getDOMNode(),
      done = this.refs.done_icon.getDOMNode(),
      progress = this.refs.progress.getDOMNode(),
      tl = new TimelineMax();
      tl.fromTo(arrow, timeAnim, {
        yPercent: 0,
        autoAlpha: 1,
        scale: 1 },
      {
        yPercent: 20,
        autoAlpha: 0,
 
        ease: Power3.easeOut }).
      fromTo(progress, 2 * timeAnim / 3, {
        yPercent: -20,
        autoAlpha: 0,
        scale: 0.6 },
      {
        yPercent: 0,
        autoAlpha: 1,
        scale: 1,
        ease: Power3.easeOut },
      "-=" + timeAnim / 3).
      to(self.state, 2 * timeAnim, {
        progress: 100,
        ease: Power0.easeNone,
        onUpdate: function (tween) {
          self.setState({
            progress: parseInt(tween.target.progress),
            action: "paused" });
        },
        onUpdateParams: ["{self}"] }).
      to(progress, timeAnim / 4, {
        yPercent: 20,
        autoAlpha: 0,
        scale: 0.6,
        delay: timeAnim / 3,
        ease: Power3.easeOut }).
      fromTo(done, timeAnim / 4, {
        yPercent: -20,
        autoAlpha: 0,
        scale: 0.6 },
      {
        yPercent: 0,
        autoAlpha: 1,
        scale: 1,
        ease: Power3.easeOut }).
      to(done, 2 * timeAnim / 3, {
        yPercent: 20,
        autoAlpha: 0,
        scale: 0.6,
        delay: timeAnim / 3,
        onStart: function () {
          self.setState({
            action: "play",
            point: "two",
            progress: 0,
            event: "" });
        },
        ease: Power3.easeOut }).
      fromTo(arrow, 2 * timeAnim / 3, {
        yPercent: -20,
        scale: 0.6,
        autoAlpha: 0 },
      {
        yPercent: 0,
        scale: 1,
        autoAlpha: 1,
        delay: timeAnim / 2,
        ease: Power3.easeOut,
        onComplete: function () {
          self.setState({
            action: "paused",
            point: "one",
            progress: 0,
            event: "" });
        } });
    }
  },
  getInitialState: function () {
    return {
      action: "paused",
      point: "",
      progress: 0,
      event: "" };
  },
  render: function () {
    return /*#__PURE__*/(
      React.createElement("div", { className: "material_button", onClick: this.handleClick }, /*#__PURE__*/
      React.createElement("i", { ref: "done_icon", className: "material-icons done" }, "done"), /*#__PURE__*/
      React.createElement("div", { ref: "progress", className: "progress" }, this.state.progress), /*#__PURE__*/
      React.createElement("i", { ref: "arrow_icon", className: "material-icons" }, "arrow_downward"), /*#__PURE__*/
      React.createElement(Ripple, { activity: this.state.action, event: this.state.event, point: this.state.point })));
  } });
React.render( /*#__PURE__*/
React.createElement(Button, null),
page);
<link rel='stylesheet' href='https://fonts.googleapis.com/icon?family=Material+Icons'>
<script src='https://cdnjs.cloudflare.com/ajax/libs/classie/1.0.1/classie.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/gsap/1.18.2/TweenMax.min.js'></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- This script got from frontendfreecode.com -->

<link rel='stylesheet' href='https://fonts.googleapis.com/icon?family=Material+Icons'>
<script src='https://cdnjs.cloudflare.com/ajax/libs/classie/1.0.1/classie.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/gsap/1.18.2/TweenMax.min.js'></script>
<style>
@import url(https://fonts.googleapis.com/css?family=Roboto:400,100,100italic,300,300italic,400italic,500,500italic,700,700italic,900,900italic&subset=latin,greek);
@import url(https://fonts.googleapis.com/css?family=Roboto+Mono:400,100,100italic,300,300italic,400italic,500,500italic,700,700italic);
html,
body {
  margin: 0;
  padding: 0;
}
body {
  font-family: 'Roboto', sans-serif;
  font-size: 100%;
  color: #1f2e3e;
  position: absolute;
  width: 100%;
  height: 100%;
}
#page {
  position: relative;
  width: 100%;
  height: 100%;
  display: -webkit-flex;
  display: flex;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-align-items: center;
  align-items: center;
  background-color: #2196f3;
}
#page.orange {
  background-color: #ff5722;
}
#page .material_button {
  position: relative;
  cursor: pointer;
  width: 64px;
  height: 64px;
  line-height: 64px;
  text-align: center;
}
#page .material_button:before {
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  content: "";
  -moz-border-radius: 50%;
  -webkit-border-radius: 50%;
  border-radius: 50%;
  position: absolute;
  -moz-box-shadow: 0 5px 11px 0 rgba(0, 0, 0, 0.18), 0 4px 15px 0 rgba(0, 0, 0, 0.15);
  -webkit-box-shadow: 0 5px 11px 0 rgba(0, 0, 0, 0.18), 0 4px 15px 0 rgba(0, 0, 0, 0.15);
  box-shadow: 0 5px 11px 0 rgba(0, 0, 0, 0.18), 0 4px 15px 0 rgba(0, 0, 0, 0.15);
  opacity: 0;
  -moz-transition: opacity 0.25s ease-out;
  -o-transition: opacity 0.25s ease-out;
  -webkit-transition: opacity 0.25s ease-out;
  transition: opacity 0.25s ease-out;
}
#page .material_button:hover:before {
  opacity: 1;
}
#page .material_button i {
  position: relative;
  height: 64px;
  width: 64px;
  line-height: 64px;
  position: relative;
  z-index: 99;
}
#page .material_button i.done {
  opacity: 0;
  visibility: hidden;
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
}
#page .material_button svg {
  position: absolute;
  top: 50%;
  left: 50%;
  -moz-transform: translate3d(-50%, -50%, 0);
  -ms-transform: translate3d(-50%, -50%, 0);
  -webkit-transform: translate3d(-50%, -50%, 0);
  transform: translate3d(-50%, -50%, 0);
  z-index: 0;
  overflow: visible;
}
#page .material_button svg circle {
  fill: #fff;
}
#page .material_button svg circle#green_ripple {
  fill: #8bc34a;
}
#page .material_button .progress {
  font-family: 'Roboto Mono', sans-serif;
  opacity: 0;
  visibility: hidden;
  position: absolute;
  width: 100%;
  height: 100%;
  text-align: center;
  z-index: 9;
}
footer {
  position: absolute;
  width: 100%;
  left: 0;
  bottom: 0;
  text-align: center;
  padding: 16px 0;
  color: #FFFFFF;
  font-size: 14px;
}
footer a {
  color: #1e59af;
}
</style>

</head>
<body>
<div id="page"></div><div id="bcl"><a style="font-size:8pt;text-decoration:none;" href="http://www.devanswer.com">Free Frontend</a></div>
<script>
function wndsize() {
  var w = 0;
  var h = 0;
  //IE
  if (!window.innerWidth) {
    if (!(document.documentElement.clientWidth == 0)) {
      //strict mode
      w = document.documentElement.clientWidth;
      h = document.documentElement.clientHeight;
    } else {
      //quirks mode
      w = document.body.clientWidth;
      h = document.body.clientHeight;
    }
  } else {
    //w3c
    w = window.innerWidth;
    h = window.innerHeight;
  }
  return {
    width: w,
    height: h };
}
// map function
Number.prototype.map = function (in_min, in_max, out_min, out_max) {
  return (this - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
};
var doc = document,
page = doc.getElementById('page'),
timeAnim = 1.25;
var Ripple = React.createClass({ displayName: "Ripple",
  getInitialState: function () {
    return {
      x: "",
      y: "",
      w: wndsize().width,
      h: wndsize().height };
  },
  rippleAnim: function (event) {
    var dom = this.refs.ripple.getDOMNode(),
    greenDom = this.refs.greenripple.getDOMNode(),
    tl = new TimelineMax(),
    offsetX = Math.abs(this.state.w / 2 - event.pageX),
    offsetY = Math.abs(this.state.h / 2 - event.pageY),
    deltaX = this.state.w / 2 + offsetX,
    deltaY = this.state.h / 2 + offsetY,
    scale_ratio = Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2));
    TweenMax.set([dom, greenDom], { transformOrigin: "center center" });
    tl.
    to(dom, timeAnim, {
      attr: {
        r: scale_ratio },
      ease: Power3.easeOut,
      onComplete: function () {
        classie.add(page, "orange");
      } }).
    to(dom, 2 * timeAnim, {
      attr: {
        r: 32 },
      delay: timeAnim / 3,
      ease: Power0.easeNone }).
    to(greenDom, timeAnim / 2, {
      attr: {
        r: scale_ratio },
      delay: timeAnim / 3,
      ease: Power3.easeOut });
  },
  componentWillReceiveProps: function (nextProps) {
    if (nextProps.activity === "play") {
      switch (nextProps.point) {
        case "one":
          this.setState({
            x: nextProps.event.pageX,
            y: nextProps.event.pageY });
          this.rippleAnim(nextProps.event);
          break;
        case "two":
          var dom = this.refs.ripple.getDOMNode(),
          greenDom = this.refs.greenripple.getDOMNode(),
          tl = new TimelineMax(),
          offsetX = Math.abs(this.state.w / 2 - this.state.x),
          offsetY = Math.abs(this.state.h / 2 - this.state.y),
          deltaX = this.state.w / 2 + offsetX,
          deltaY = this.state.h / 2 + offsetY,
          scale_ratio = Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2));
          tl.
          to(dom, timeAnim, {
            attr: {
              r: scale_ratio },
            onComplete: function () {
              classie.remove(page, "orange");
              TweenMax.set(greenDom, {
                attr: {
                  r: 32 } });
            },
            ease: Power3.easeOut }).
          to(dom, timeAnim / 2, {
            attr: {
              r: 32 },
            ease: Power3.easeOut });
          break;}
    }
  },
  render: function () {
    return /*#__PURE__*/(
      React.createElement("svg", { height: "1", width: "1" }, /*#__PURE__*/
      React.createElement("circle", { ref: "greenripple", id: "green_ripple", cx: "0", cy: "0", r: "32" }), /*#__PURE__*/
      React.createElement("circle", { ref: "ripple", id: "white_ripple", cx: "0", cy: "0", r: "32" })));
  } });
var Button = React.createClass({ displayName: "Button",
  handleClick: function (e) {
    var self = this;
    if (this.state.action === "paused") {
      this.setState({
        action: "play",
        point: "one",
        progress: 0,
        event: e.nativeEvent });
      var arrow = this.refs.arrow_icon.getDOMNode(),
      done = this.refs.done_icon.getDOMNode(),
      progress = this.refs.progress.getDOMNode(),
      tl = new TimelineMax();
      tl.fromTo(arrow, timeAnim, {
        yPercent: 0,
        autoAlpha: 1,
        scale: 1 },
      {
        yPercent: 20,
        autoAlpha: 0,
 
        ease: Power3.easeOut }).
      fromTo(progress, 2 * timeAnim / 3, {
        yPercent: -20,
        autoAlpha: 0,
        scale: 0.6 },
      {
        yPercent: 0,
        autoAlpha: 1,
        scale: 1,
        ease: Power3.easeOut },
      "-=" + timeAnim / 3).
      to(self.state, 2 * timeAnim, {
        progress: 100,
        ease: Power0.easeNone,
        onUpdate: function (tween) {
          self.setState({
            progress: parseInt(tween.target.progress),
            action: "paused" });
        },
        onUpdateParams: ["{self}"] }).
      to(progress, timeAnim / 4, {
        yPercent: 20,
        autoAlpha: 0,
        scale: 0.6,
        delay: timeAnim / 3,
        ease: Power3.easeOut }).
      fromTo(done, timeAnim / 4, {
        yPercent: -20,
        autoAlpha: 0,
        scale: 0.6 },
      {
        yPercent: 0,
        autoAlpha: 1,
        scale: 1,
        ease: Power3.easeOut }).
      to(done, 2 * timeAnim / 3, {
        yPercent: 20,
        autoAlpha: 0,
        scale: 0.6,
        delay: timeAnim / 3,
        onStart: function () {
          self.setState({
            action: "play",
            point: "two",
            progress: 0,
            event: "" });
        },
        ease: Power3.easeOut }).
      fromTo(arrow, 2 * timeAnim / 3, {
        yPercent: -20,
        scale: 0.6,
        autoAlpha: 0 },
      {
        yPercent: 0,
        scale: 1,
        autoAlpha: 1,
        delay: timeAnim / 2,
        ease: Power3.easeOut,
        onComplete: function () {
          self.setState({
            action: "paused",
            point: "one",
            progress: 0,
            event: "" });
        } });
    }
  },
  getInitialState: function () {
    return {
      action: "paused",
      point: "",
      progress: 0,
      event: "" };
  },
  render: function () {
    return /*#__PURE__*/(
      React.createElement("div", { className: "material_button", onClick: this.handleClick }, /*#__PURE__*/
      React.createElement("i", { ref: "done_icon", className: "material-icons done" }, "done"), /*#__PURE__*/
      React.createElement("div", { ref: "progress", className: "progress" }, this.state.progress), /*#__PURE__*/
      React.createElement("i", { ref: "arrow_icon", className: "material-icons" }, "arrow_downward"), /*#__PURE__*/
      React.createElement(Ripple, { activity: this.state.action, event: this.state.event, point: this.state.point })));
  } });
React.render( /*#__PURE__*/
React.createElement(Button, null),
page);
</script>

</body>
</html>
Preview