首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >react状态更改状态以使代码从可见变为隐藏

react状态更改状态以使代码从可见变为隐藏
EN

Stack Overflow用户
提问于 2018-07-31 23:11:18
回答 1查看 25关注 0票数 0

我正在尝试使用按钮来更改显示,以使用状态显示新的代码。现在按钮还没有从.hidden切换到.show。我想单击该按钮,然后弹出.binocularView、.binocularText和resumeDownload。

代码语言:javascript
复制
import React from "react";
import Link from "next/link";

class test extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      showHideView: "hidden"
    };
  }

  render() {
    return (
      <div>
        <div className="firstPage">
          <h1> Looking for a Project Manager? </h1>
          <h2> Take a peek inside </h2>
          <div className="buttonContainer">
            <button
              onClick={this.toggleView.bind(this)}
              className="binocularButton"
            >
              <div className={this.state.showHideView}>
                <div className="binocularView">
                  <h6 className="binocluarText">I am looking for you too</h6>
                  <a
                    className="resume-download"
                    href="/static/ScottFosterResume.pdf"
                    download="Scott-Foster-Resume"
                  >
                    Download PDF Resume
                  </a>
                </div>
              </div>
            </button>
          </div>
        </div>

        <style jsx>{`
          @import url("https://fonts.googleapis.com/css?family=EB+Garamond|Quicksand");
          @font-face {
            font-family: "EB Garamond", serif;
            src: url("../static/fonts/ebgaramond/EBGaramond-Regular.ttf")
              format("truetype");
          }
          h1 {
            text-align: center;
            justify-self: center;
            font-family: "EB Garamond", serif;
          }
          h2 {
            text-align: center;
            justify-self: center;
            font-family: "EB Garamond", serif;
          }
          .firstPage {
            height: 100%;
            width: 100%;
            position: fixed;
            background-image: url("/static/img/binoculars-fog-foggy-1136815.jpg");
            -webkit-background-size: cover;
            -moz-background-size: cover;
            -o-background-size: cover;
            background-size: cover;
          }
          .buttonContainer {
            position: fixed;
            height: 100%;
            width: 100%;
          }
          .binocularButton {
            height: 9%;
            width: 9%;
            position: relative;
            color: white;
            cursor: pointer;
            justify-content: center;
            margin-top: 12%;
            margin-left: 40%;
            padding: 10%;
            border-radius: 50%;
            opacity: 0;
            z-index: 1;
          }
          .show {
            visibility: visable;
          }
          .hidden {
            visibility: hidden;
            display: none;
          }
          .binocularView {
            transform: scale(5);
            transform: 100s ease-in-out;
            opacity: 1;
            background-attachment: inherit;
            background-image: url("/static/img/DSCF6548.jpg");
            background-size: cover;
            position: fixed;
            top: 20%;
            left: 5%;
            width: 35%;
            display: block;
            align-items: top;
          }
          .binocluarText {
            color: black;
            width: ;
          }
          .resume-download {
            text-decoration: none;
            background: #054a25;
            color: white;
            padding: 5px;
            justify-content: flex-start;
          }
        `}</style>
      </div>
    );
  }

  toggleView() {
    var css = this.state.showHideView === "hidden" ? "hidden" : "show";
    this.setState({ showHideView: css });
  }
}

export default test;
EN

回答 1

Stack Overflow用户

发布于 2018-07-31 23:13:47

变化

代码语言:javascript
复制
var css = (this.state.showHideView === "hidden") ? "hidden" : "show";

代码语言:javascript
复制
var css = (this.state.showHideView === "hidden") ? "show" : "hidden";
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51616646

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档