【发布时间】:2021-02-09 04:16:25
【问题描述】:
我已经采取了突破,在底部留下一个,重新排列了先出现的情况的顺序,并且还在大于/小于/等之间切换...与包括中断,它会遇到第一个或最后一个案例,具体取决于您使用的是“=”。
constructor (props) {
super(props);
this.state = { clicked: false, windowWidth: window.innerWidth };
this.welcomeBtn = this.welcomeBtn.bind(this);
}
componentDidMount() {
console.log(this.state.windowWidth);
const windowCheck = window.innerWidth;
this.setState({
windowWidth: windowCheck
});
}
welcomeBtn() {
console.log(this.state.windowWidth);
var windowWidthString = this.state.windowWidth;
switch(true) {
case (windowWidthString <= 300):
window.scrollTo({top: 100, behavior: 'smooth'});
break;
case (windowWidthString <= 350):
window.scrollTo({top: 1100, behavior: 'smooth'});
break;
case (windowWidthString <= 700):
window.scrollTo({top: 500, behavior: 'smooth'});
break;
case (windowWidthString <= 900):
window.scrollTo({top: 900, behavior: 'smooth'});
break;
case (windowWidthString <= 1100):
window.scrollTo({top: 1100, behavior: 'smooth'});
break;
}
}
render () {
return(
<div>
<div id="welcomeMessageDiv">
<h1 className="headTitle">Welcome</h1>
<button onClick={this.welcomeBtn}>Learn More</button>
</div>
<Parallax y={[-20, 20]}>
<div>{stuff}<div>
</Parallax>
<div id="moreInfoDivHome">
</div>
</div>
)
}
}
【问题讨论】:
标签: reactjs switch-statement logical-operators