0
このユーザーのボックスをクリックすると、私のコードのロジックは、私はdrag-and-resize-box-text clicked
を返しますtrue
とgetCssStyle()
に状態active
を設定しますされ、その後、背景画像(T
は)新しいCSSスタイルにレンダリングされませんでしたリアクト
class Box extends Component {
constructor(props) {
super(props);
this.state = {
active: false,
}
}
// decide which style to be used
getCssStyle = (type) => {
switch (type) {
case 'text':
if (this.state.active) {
console.log("AAA")
return 'drag-and-resize-box-text clicked'
} else {
console.log("BBB")
return 'drag-and-resize-box-text';
}
// break;
default:
return '';
}
}
onClick =() => {
this.setState({active: true});
}
render() {
return (
<div className={this.getCssStyle(boxType)} >
{this.boxFillContent()}
</div>
</div>
);
}
}
devツールは背景画像が削除されていることを示していますが、ページにはまだ画像が表示されています
何が問題なのですか?
CSS
.drag-and-resize-box-text{
border: dashed 3px LightSeaGreen;
background: url(../images/bottom/text_normal.png) no-repeat;
background-position:center;
width: inherit;
height: inherit;
}
.drag-and-resize-box-text.clicked{
border: dashed 3px LightSeaGreen;
/*background: url(../images/bottom/text_normal.png) no-repeat;*/
background-position:center;
width: inherit;
height: inherit;
}
を使用することによって大幅に簡素化することができ
ありがとうございました! 'background:none'はうまく動作し、コードははるかに優れています! – user2492364