目前,我有一个使用CSS制作的进度条,其宽度为百分比。如果要增加宽度的大小,我该怎么做?在功能中,handleNextButtonClick()
您可以看到我的操作方式。由于存在,因此无法递增添加问题px
。
const Quiz = () => {
let answer = 0;
const [value, setValue] = useState(1);
const [score, setScore] = useState(0);
const [currentQuestion, setCurrentQuestion] = useState(0);
const [width, setWidth] = useState(0);
const [showScore, setShowScore] = useState(false);
const onChange = (e) => {
console.log('qustion checked', e.target.value);
setValue(e.target.value);
};
const handleNextButtonClick = () => {
const nextQuestion = currentQuestion + 1;
const scoreValue = score + 1;
if (nextQuestion < Questions.length) {
if (value === Questions[currentQuestion].answer) {
setScore(scoreValue);
setCurrentQuestion(nextQuestion);
} else {
setCurrentQuestion(nextQuestion);
}
} else {
setShowScore(true);
console.log(score);
}
var progressBar = document.getElementById('main');
const currentWidth = width + 600 / Questions.length + 'px';
setWidth(currentWidth);
progressBar.style.width = currentWidth;
console.log(currentWidth);
// const updateProgress = currentProgress + (100/Questions.length)
// setCurrentProgress(updateProgress);
};
return (
<div className="QuizBox">
{showScore ? (
<h1>
Du fik {score} ud af {Questions.length}
</h1>
) : (
<>
<div className="Header">Cybersikkerheds Quiz</div>
<Row>
<Col span={23}>
<ProgressBar />
<div className="Question">{Questions[currentQuestion].questionText}</div>
<Radio.Group onChange={onChange} value={value} buttonStyle="solid">
{Questions[currentQuestion].answerOptions.map((item) => {
return (
<Radio.Button key={item.answerText} value={answer++}>
{item.answerText}
</Radio.Button>
);
})}
<Button onClick={() => handleNextButtonClick()} type="primary">
Næste
</Button>
</Radio.Group>
</Col>
</Row>
</>
)}
</div>
);
};
export default Quiz;
让width
仍然是一个号码,追加'px'
设置进度条的宽度属性时:
const currentWidth = width + 600 / Questions.length;
setWidth(currentWidth);
progressBar.style.width = currentWidth + 'px';
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句