目前,我可以改变字体大小一次:减少(—A),默认(A)或增加(A+).如果我点击按钮不止一次,它什么也不做.
我想要的是能够增加/减少字体大小,但限制它点击两次,使字体大小不超过—/+150%.
示例:当我点击-A
时,字体大小减小到0.75em.我希望这进一步减少到0.5em,如果有人再次点击它,但这应该是最小大小,它可以go .同样,当点击A+
时,字体大小会增加到1.25em,但如果用户多次点击,字体大小不会超过1.5em.
Demo: 100
Html:
<button type="button" onclick="changeSizeByBtn(0.75)" name="btn1">-A</button>
<button type="button" onclick="changeSizeByBtn(1)" name="btn2">A</button>
<button type="button" onclick="changeSizeByBtn(1.25)" name="btn3">A+</button>
<hr />
<div id="container">
<h1>This is the title</h1>
<h2>This is a sub title</h2>
<p>I need to increase the texts here by clicking on A+ button and decrease them by clicking -A button above. <br />
The problem here is that it increase/decrease only once. I want it to increase or decrease twice by say 25%. Not Thrice but just twice. How can I go about doing this?</p>
</div>
JS:
var cont = document.getElementById("container");
function changeSizeByBtn(size) {
cont.style.fontSize = size + "em";
}
Css:以下内容:
div {
padding: 20px;
border: 5px solid red;
}
h1 {
font-size: 2em;
}
h2 {
font-size: 1.5em;
}
p {
font-size: 1em;
}