content logo

React Buttons:

Sliding Show/Hide React Button Effect

In this post, you will see buttons that have a raised shape. The title of these buttons is white, but their colors are different. You can hide the red button by clicking on the green button. By hiding the red button, the green button also changes its title. These buttons use React and can be used to reduce the physical space on websites.

#

React Hiding Effect

#

Sliding Button Code

#

React Sliding Button Effect

#

React Text Change Effect

<!-- This script got from frontendfreecode.com -->
<div id="main"></div><a style="font-size: 8pt; text-decoration: none" target="_blank" href="http://frontendfreecode.com">Free Frontend</a>
                                                                            
body {
  background-color: #34495e;
}
.btn-slide {
  margin: 2px;
  text-decoration: none;
  padding: 4px 8px 4px 8px;
  display: inline-block;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid #3b6e22;
  transition: all 500ms ease-in-out;
}
.btn-slide-success {
  background: linear-gradient(lightgreen, green);
  color: white;
}
.btn-slide-success:hover {
  color: yellow;
}
.btn-slide-warn {
  background: linear-gradient(crimson, darkred);
  color: white;
}
.btn-slide-warn:hover {
  color: yellow;
}
.btn-slide-hidden {
  opacity: 0;
  margin-left: -100px;
}
.btn-slide-visible {
  opacity: 1;
  margin-left: 0;
}
var SlideButton = React.createClass({ displayName: "SlideButton",
  handleClick: function (e) {
    if (this.props.onClick) {
      this.props.onClick(e);
    }
  },
  render: function () {
    var className = 'btn-slide ' + this.props.className;
    if (this.props.visible === undefined || this.props.visible == true) {
      className += ' btn-slide-visible';
    } else {
      className += ' btn-slide-hidden';
    }
    return /*#__PURE__*/(
      React.createElement("a", { href: "#", className: className, onClick: this.handleClick },
      this.props.children));
  } });
var Application = React.createClass({ displayName: "Application",
  getInitialState: function () {
    return { buttonVisible: true };
  },
  onShowHide: function () {
    this.setState({ buttonVisible: !this.state.buttonVisible });
  },
  render: function () {
    var toggleText = this.state.buttonVisible ? 'Hide' : 'Show';
    return /*#__PURE__*/(
      React.createElement("div", null, /*#__PURE__*/
      React.createElement("h1", null, "Sliding Button - React.js"), /*#__PURE__*/
      React.createElement(SlideButton, { visible: this.state.buttonVisible, className: "btn-slide-warn" }, "Slide Button"), /*#__PURE__*/
      React.createElement(SlideButton, { onClick: this.onShowHide, className: "btn-slide-success" }, toggleText)));
  } });
React.render( /*#__PURE__*/
React.createElement(Application, null),
document.getElementById('main'));
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/0.14.3/react.min.js'></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- This script got from frontendfreecode.com -->

<script src='https://cdnjs.cloudflare.com/ajax/libs/react/0.14.3/react.min.js'></script>
<style>
body {
  background-color: #34495e;
}
.btn-slide {
  margin: 2px;
  text-decoration: none;
  padding: 4px 8px 4px 8px;
  display: inline-block;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid #3b6e22;
  transition: all 500ms ease-in-out;
}
.btn-slide-success {
  background: linear-gradient(lightgreen, green);
  color: white;
}
.btn-slide-success:hover {
  color: yellow;
}
.btn-slide-warn {
  background: linear-gradient(crimson, darkred);
  color: white;
}
.btn-slide-warn:hover {
  color: yellow;
}
.btn-slide-hidden {
  opacity: 0;
  margin-left: -100px;
}
.btn-slide-visible {
  opacity: 1;
  margin-left: 0;
}
</style>

</head>
<body>
<div id="main"></div><div id="bcl"><a style="font-size:8pt;text-decoration:none;" href="http://www.devanswer.com">Free Frontend</a></div>
<script>
var SlideButton = React.createClass({ displayName: "SlideButton",
  handleClick: function (e) {
    if (this.props.onClick) {
      this.props.onClick(e);
    }
  },
  render: function () {
    var className = 'btn-slide ' + this.props.className;
    if (this.props.visible === undefined || this.props.visible == true) {
      className += ' btn-slide-visible';
    } else {
      className += ' btn-slide-hidden';
    }
    return /*#__PURE__*/(
      React.createElement("a", { href: "#", className: className, onClick: this.handleClick },
      this.props.children));
  } });
var Application = React.createClass({ displayName: "Application",
  getInitialState: function () {
    return { buttonVisible: true };
  },
  onShowHide: function () {
    this.setState({ buttonVisible: !this.state.buttonVisible });
  },
  render: function () {
    var toggleText = this.state.buttonVisible ? 'Hide' : 'Show';
    return /*#__PURE__*/(
      React.createElement("div", null, /*#__PURE__*/
      React.createElement("h1", null, "Sliding Button - React.js"), /*#__PURE__*/
      React.createElement(SlideButton, { visible: this.state.buttonVisible, className: "btn-slide-warn" }, "Slide Button"), /*#__PURE__*/
      React.createElement(SlideButton, { onClick: this.onShowHide, className: "btn-slide-success" }, toggleText)));
  } });
React.render( /*#__PURE__*/
React.createElement(Application, null),
document.getElementById('main'));
</script>

</body>
</html>
Preview