content logo

React Buttons:

React 3D Button Code with Rotation Effect on Hover

You can use attractive buttons to enter important sections on your website. One of these buttons is given in this post. This button has a hover effect. Using this button, you can attract more attention of your website user. This button rotates when the mouse is placed on it and shows a different title.

#

React Button Code

#

HTML 3D Button

#

3D React Button Rotation

#

Animating HTML Button

<!-- This script got from frontendfreecode.com -->
<div id="app"></div><a style="font-size: 8pt; text-decoration: none" target="_blank" href="http://frontendfreecode.com">Free Frontend</a>
                                                                            
html,
body {
  height: 100%;
  overflow: hidden;
}
body {
  color: #6699CC;
  font-size: 22px;
  font-weight: bold;
  text-align: center;
  -webkit-font-smoothing: antialiased;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #C594C5;
  background-size: cover;
  background-position: center;
  background-image: linear-gradient(rgba(173, 216, 230, 0.4), rgba(221, 160, 221, 0.4)), url("https://i.imgsafe.org/1fee5c9.jpg");
}
.fancy-button {
  position: relative;
  display: block;
  cursor: pointer;
  perspective: 1800px;
}
.fancy-button .fancy-flipper {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  transform-style: preserve-3d;
  transform: rotateX(-90deg);
  transition: transform 0.3s ease;
}
.fancy-button .fancy-front,
.fancy-button .fancy-back {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  -webkit-backface-visibility: hidden;
          backface-visibility: hidden;
}
.fancy-button .fancy-front svg,
.fancy-button .fancy-back svg {
  display: block;
}
.fancy-button:hover .fancy-flipper {
  transform: rotateX(0deg);
}
.fancy-button:active .fancy-flipper {
  transform: rotateX(0deg) scale(0.95);
  transition: transform 0.05s ease;
}
.fancy-button .button-text {
  letter-spacing: 0.01em;
  font-family: Futura, "Helvetica Neue", Helvetica, sans-serif;
}
class FancyButton extends React.Component {
    render() {
        const maskId = 'mask_1';
        const maskStyle = '#fancy-masked-element_' + maskId + ' { mask: url(#' + maskId + '); -webkit-mask: url(#' + maskId + ')}';
        const buttonStyle = {
            width: this.props.width,
            height: this.props.height
        };
        const fancyFrontStyle = {
            transform: 'rotateX(0deg) translateZ(' + this.props.height / 2 + 'px )'
        };
        const fancyBackStyle = {
            transform: 'rotateX(90deg) translateZ( ' + this.props.height / 2 + 'px )'
        };
        const textTransform = 'matrix(1 0 0 1 ' + this.props.width / 2 + ' ' + this.props.height / 1.6 + ')';
        const viewBox = '0 0 ' + this.props.width + ' ' + this.props.height;
        return(
            React.createElement("div", {
                className: "fancy-button",
                style: buttonStyle,
                ref: "fancyButton"
            },
                React.createElement("div", { className: "fancy-flipper" }, /*#__PURE__*/
                    React.createElement("div", { className: "fancy-front", style: fancyFrontStyle }, /*#__PURE__*/
                        React.createElement("svg", {
                            height: this.props.height,
                            width: this.props.width,
                            viewBox: viewBox
                        }, /*#__PURE__*/
                            React.createElement("defs", null, /*#__PURE__*/
                                React.createElement("mask", { id: maskId }, /*#__PURE__*/
                                    React.createElement("rect", { width: "100%", height: "100%", fill: "#FFFFFF" }), /*#__PURE__*/
                                    React.createElement("text", { className: "mask-text button-text", fill: "#000000", transform: textTransform, fontFamily: "'intro_regular'", fontSize: this.props.fontSize, width: "100%", textAnchor: "middle", letterSpacing: "1" }, this.props.buttonText))), /*#__PURE__*/
                            React.createElement("style", null,
                                maskStyle), /*#__PURE__*/
                            React.createElement("rect", { id: 'fancy-masked-element_' + maskId, fill: this.props.color, width: "100%", height: "100%" }))), /*#__PURE__*/
                    React.createElement("div", { className: "fancy-back", style: fancyBackStyle }, /*#__PURE__*/
                        React.createElement("svg", {
                            height: this.props.height,
                            width: this.props.width,
                            viewBox: viewBox
                        }, /*#__PURE__*/
                            React.createElement("rect", {
                                stroke: this.props.color,
                                strokeWidth: this.props.borderWidth,
                                fill: "transparent",
                                width: "100%",
                                height: "100%"
                            }), /*#__PURE__*/
                            React.createElement("text", { className: "button-text", transform: textTransform, fill: this.props.color, fontFamily: "'intro_regular'", fontSize: this.props.fontSize, textAnchor: "middle", letterSpacing: "1" }, this.props.buttonText))))));
    }
}
FancyButton.defaultProps = {
    color: '#FFFFFF',
    width: 410,
    height: 100,
    fontSize: 40,
    borderWidth: 15,
    buttonText: 'FANCY BUTTON'
};
React.render( /*#__PURE__*/React.createElement(FancyButton, null), document.getElementById('app'));
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/0.14.2/react.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.2/react.js'></script>
<style>
html,
body {
  height: 100%;
  overflow: hidden;
}
body {
  color: #6699CC;
  font-size: 22px;
  font-weight: bold;
  text-align: center;
  -webkit-font-smoothing: antialiased;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #C594C5;
  background-size: cover;
  background-position: center;
  background-image: linear-gradient(rgba(173, 216, 230, 0.4), rgba(221, 160, 221, 0.4)), url("https://i.imgsafe.org/1fee5c9.jpg");
}
.fancy-button {
  position: relative;
  display: block;
  cursor: pointer;
  perspective: 1800px;
}
.fancy-button .fancy-flipper {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  transform-style: preserve-3d;
  transform: rotateX(-90deg);
  transition: transform 0.3s ease;
}
.fancy-button .fancy-front,
.fancy-button .fancy-back {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  -webkit-backface-visibility: hidden;
          backface-visibility: hidden;
}
.fancy-button .fancy-front svg,
.fancy-button .fancy-back svg {
  display: block;
}
.fancy-button:hover .fancy-flipper {
  transform: rotateX(0deg);
}
.fancy-button:active .fancy-flipper {
  transform: rotateX(0deg) scale(0.95);
  transition: transform 0.05s ease;
}
.fancy-button .button-text {
  letter-spacing: 0.01em;
  font-family: Futura, "Helvetica Neue", Helvetica, sans-serif;
}
</style>

</head>
<body>
<div id="app"></div><div id="bcl"><a style="font-size:8pt;text-decoration:none;" href="http://www.devanswer.com">Free Frontend</a></div>
<script>
class FancyButton extends React.Component {
    render() {
        const maskId = 'mask_1';
        const maskStyle = '#fancy-masked-element_' + maskId + ' { mask: url(#' + maskId + '); -webkit-mask: url(#' + maskId + ')}';
        const buttonStyle = {
            width: this.props.width,
            height: this.props.height
        };
        const fancyFrontStyle = {
            transform: 'rotateX(0deg) translateZ(' + this.props.height / 2 + 'px )'
        };
        const fancyBackStyle = {
            transform: 'rotateX(90deg) translateZ( ' + this.props.height / 2 + 'px )'
        };
        const textTransform = 'matrix(1 0 0 1 ' + this.props.width / 2 + ' ' + this.props.height / 1.6 + ')';
        const viewBox = '0 0 ' + this.props.width + ' ' + this.props.height;
        return(
            React.createElement("div", {
                className: "fancy-button",
                style: buttonStyle,
                ref: "fancyButton"
            },
                React.createElement("div", { className: "fancy-flipper" }, /*#__PURE__*/
                    React.createElement("div", { className: "fancy-front", style: fancyFrontStyle }, /*#__PURE__*/
                        React.createElement("svg", {
                            height: this.props.height,
                            width: this.props.width,
                            viewBox: viewBox
                        }, /*#__PURE__*/
                            React.createElement("defs", null, /*#__PURE__*/
                                React.createElement("mask", { id: maskId }, /*#__PURE__*/
                                    React.createElement("rect", { width: "100%", height: "100%", fill: "#FFFFFF" }), /*#__PURE__*/
                                    React.createElement("text", { className: "mask-text button-text", fill: "#000000", transform: textTransform, fontFamily: "'intro_regular'", fontSize: this.props.fontSize, width: "100%", textAnchor: "middle", letterSpacing: "1" }, this.props.buttonText))), /*#__PURE__*/
                            React.createElement("style", null,
                                maskStyle), /*#__PURE__*/
                            React.createElement("rect", { id: 'fancy-masked-element_' + maskId, fill: this.props.color, width: "100%", height: "100%" }))), /*#__PURE__*/
                    React.createElement("div", { className: "fancy-back", style: fancyBackStyle }, /*#__PURE__*/
                        React.createElement("svg", {
                            height: this.props.height,
                            width: this.props.width,
                            viewBox: viewBox
                        }, /*#__PURE__*/
                            React.createElement("rect", {
                                stroke: this.props.color,
                                strokeWidth: this.props.borderWidth,
                                fill: "transparent",
                                width: "100%",
                                height: "100%"
                            }), /*#__PURE__*/
                            React.createElement("text", { className: "button-text", transform: textTransform, fill: this.props.color, fontFamily: "'intro_regular'", fontSize: this.props.fontSize, textAnchor: "middle", letterSpacing: "1" }, this.props.buttonText))))));
    }
}
FancyButton.defaultProps = {
    color: '#FFFFFF',
    width: 410,
    height: 100,
    fontSize: 40,
    borderWidth: 15,
    buttonText: 'FANCY BUTTON'
};
React.render( /*#__PURE__*/React.createElement(FancyButton, null), document.getElementById('app'));
</script>

</body>
</html>
Preview