4
I’m having trouble developing when we talk about for... The basics I can understand now in practice... People have developed this code and I believe it can be reduced to a few lines with for.
Notice that when changing the input range, it appears different buttons (the determined ones) and closes the open button Ivs. When we press these buttons he opens his div and closes the rest.
If necessary I have made available the simplified code below!
Here begins the Js
/* Dinâmica do Input Range */
function updateTextInput(val) {
/* Para controlar os Botões */
if(val == 1){
document.getElementById('um').style.display = "block";
document.getElementById('dois').style.display = "block";
document.getElementById('tres').style.display = "none";
document.getElementById('quatro').style.display = "none";
document.getElementById('cinco').style.display = "none";
}
if(val == 2){
document.getElementById('um').style.display = "block";
document.getElementById('dois').style.display = "block";
document.getElementById('tres').style.display = "block";
document.getElementById('quatro').style.display = "none";
document.getElementById('cinco').style.display = "none";
}
if(val == 3){
document.getElementById('um').style.display = "block";
document.getElementById('dois').style.display = "block";
document.getElementById('tres').style.display = "block";
document.getElementById('quatro').style.display = "block";
document.getElementById('cinco').style.display = "none";
}
if(val == 4){
document.getElementById('um').style.display = "block";
document.getElementById('dois').style.display = "block";
document.getElementById('tres').style.display = "block";
document.getElementById('quatro').style.display = "block";
document.getElementById('cinco').style.display = "block";
}
/* Para controlar as Slide's Div */
document.getElementById('slideum').style.display = "none";
document.getElementById('slidedois').style.display = "none";
document.getElementById('slidetres').style.display = "none";
document.getElementById('slidequatro').style.display = "none";
document.getElementById('slidecinco').style.display = "none";
}
/* Dinâmica do Input Button */
function slideumf(){
document.getElementById('slideum').style.display = "block";
document.getElementById('slidedois').style.display = "none";
document.getElementById('slidetres').style.display = "none";
document.getElementById('slidequatro').style.display = "none";
document.getElementById('slidecinco').style.display = "none";
}
function slidedoisf(){
document.getElementById('slideum').style.display = "none";
document.getElementById('slidedois').style.display = "block";
document.getElementById('slidetres').style.display = "none";
document.getElementById('slidequatro').style.display = "none";
document.getElementById('slidecinco').style.display = "none";
}
function slidetresf(){
document.getElementById('slideum').style.display = "none";
document.getElementById('slidedois').style.display = "none";
document.getElementById('slidetres').style.display = "block";
document.getElementById('slidequatro').style.display = "none";
document.getElementById('slidecinco').style.display = "none";
}
function slidequatrof(){
document.getElementById('slideum').style.display = "none";
document.getElementById('slidedois').style.display = "none";
document.getElementById('slidetres').style.display = "none";
document.getElementById('slidequatro').style.display = "block";
document.getElementById('slidecinco').style.display = "none";
}
function slidecincof(){
document.getElementById('slideum').style.display = "none";
document.getElementById('slidedois').style.display = "none";
document.getElementById('slidetres').style.display = "none";
document.getElementById('slidequatro').style.display = "none";
document.getElementById('slidecinco').style.display = "block";
}
</script>
Here begins the CSS
/* Style Inicial dos Inputs Button */
#um{display: none;}
#dois{display: none;}
#tres{display: none;}
#quatro{display: none;}
#cinco{display: none;}
/* Style Inicial das Div's dos Slides */
#slideum{display: none;}
#slidedois{display: none;}
#slidetres{display: none;}
#slidequatro{display: none;}
#slidecinco{display: none;}
</style>
</head>
Here Begins the HTML5
<input type="range" name="rangeInput" min="1" max="4" onchange="updateTextInput(this.value);">
<input id="um" type="button" value="1º Slide" onclick="slideumf()">
<div id="slideum">
<input type="range" min="1" max="5"><div id="slideum">1º Slide</div>
<input id="dois" type="button" value="2º Slide" onclick="slidedoisf()">
<div id="slidedois">2º Slide</div>
<input id="tres" type="button" value="3º Slide" onclick="slidetresf()">
<div id="slidetres">3º Slide</div>
<input id="quatro" type="button" value="4º Slide" onclick="slidequatrof()">
<div id="slidequatro">4º Slide</div>
<input id="cinco" type="button" value="5º Slide" onclick="slidecincof()">
<div id="slidecinco">5º Slide</div>
</body>
Post HTML as well, if possible. Otherwise we won’t be able to test possible solutions.
– mau humor
When I posted the question, she was already following the HTML. It’s down there, kkk It’s really short!
– Giancarlo Soldera Graziano
A yes, had not rolled enough. But it is good to separate when posting.
– mau humor
I’m new to the forum, I haven’t learned the tricks yet! I’ll try!
– Giancarlo Soldera Graziano
One thing I realized is that the first two buttons are always used. So you can delete the first one
if
of the first function and leave the first two lines before the if’s.– mutlei
Mutlei, well noted but early on only the input range is visible... But you can still leave 1 and 2 displayBlock independent of if on onchange!
– Giancarlo Soldera Graziano