I need to display up to eight bottles when the input value is greater than 100.
I have a function updateWaterLevel()
that updates the water level in the first bottle, but I’m unsure how to update the other bottles.
let inputWaterLevel = document.querySelector('[name=water-level]');
let heightLiquid = +tubeLiquid.getAttribute('height');
let yLiquid = +tubeLiquid.getAttribute('y');
let liquidPercent = heightLiquid/100;
inputWaterLevel.addEventListener('input', updateWaterLevel);
function updateWaterLevel() {
let value = +this.value;
let height = liquidPercent * value;
let y = yLiquid + (heightLiquid-height);
tubeLiquid.setAttribute('height', liquidPercent * value )
tubeLiquid.setAttribute('y', y )
}
I have added a new function addBottle2()
to add a second bottle when the input value is greater than 100, but I am still having trouble adding more bottles up to eight.
let addBottle2 = () => {
inputWaterLevel.id = 'inpId';
let inpId = document.getElementById('inpId')
inpId.addEventListener("input", () => {
if (inpId.value > 100) {
document.getElementById("bot2").style.display = 'block';
}
else if (inpId.value <= 100){
document.getElementById("bot2").style.display = 'none';
}
});
}
addBottle2()
.cont{
display: flex;
}
#bot2{
display: none;
}
<p><input type="number" min="0" max="200" value="100" name="water-level" /></p>
<div class="cont">
<div class="bot1">
<svg viewBox="0 0 300 300" width="150">
<clipPath id="clip">
<rect x="118" y="68" width="64" height="228" rx="20" ry="20" />
</clipPath>
<image width="300" xlink:href="https://i.ibb.co/HGFQYTj/bottle.png" />
<rect clip-path="url(#clip)" id="tubeLiquid" x="115" y="58" width="70" height="233" fill="#74ccf4" />
</svg>
</div>
<div id="bot2">
<svg viewBox="0 0 300 300" width="150">
<clipPath id="clip2">
<rect x="118" y="68" width="64" height="228" rx="20" ry="20" />
</clipPath>
<image width="300" xlink:href="https://i.ibb.co/HGFQYTj/bottle.png" />
<rect clip-path="url(#clip2)" id="tubeLiquid2" x="115" y="58" width="70" height="233" fill="#74ccf4" />
</svg>
</div>
</div>
I need to add up to seven additional bottles when the input value is greater than 100.