Je réserve
HTML
<div id="contenu">
<form>
<fieldset>
<button type="button" id="moins" onclick="doLess();">
<svg viewbox="0 0 28 28" stroke-width="2">
<circle cx="14" cy="14" r="13"/>
<line x1="10" y1="14" x2="18" y2="14"/>
</svg>
</button>
<div id="num">
<div id="innum">
<span>1</span>
</div>
</div>
<button type="button" id="plus" onclick="doMore();">
<svg viewbox="0 0 28 28" stroke-width="2">
<circle cx="14" cy="14" r="13"/>
<line x1="9" y1="14" x2="19" y2="14"/>
<line x1="14" y1="9" x2="14" y2="19"/>
</svg>
</button>
<button type="button" id="fois" onclick="doReserve();">
<svg viewbox="0 0 28 28" stroke-width="2">
<circle cx="14" cy="14" r="13"/>
<line x1="9" y1="9" x2="19" y2="19"/>
<line x1="9" y1="19" x2="19" y2="9"/>
</svg>
</button>
</fieldset>
<fieldset>
<input type="hidden" name="num" value="1">
<input type="submit" value="Je réserve">
</fieldset>
</form>
</div>
CSS
body {
margin: 0;
padding: 0;
}
#contenu {
width: 16rem;
height: 4rem;
margin: 0 auto;
background: #eea595;
box-shadow: 0 0.5rem 0.25rem #eaeaea;
}
form {
font-family: arial, sans-serif;
position: absolute;
left: calc(50% - 8rem);
top: 2.5rem;
width: 16rem;
height: 5rem;
margin: 0;
padding: 0;
overflow: hidden;
}
fieldset {
border: 0;
margin: 0;
padding: 0;
position: absolute;
display: block;
left: 0;
right: 0;
height: 5rem;
transition: top 0.5s ease;
}
fieldset:first-of-type {
top: 0;
}
fieldset:last-of-type {
top: -5rem;
}
[type="submit"],
button {
display: block;
box-sizing: content-box;
font-size: 1rem;
font-family: arial, sans-serif;
position: absolute;
font-weight: bold;
text-align: center;
padding: 0;
margin: 0;
}
[type="submit"]:focus,
button:focus {
outline: 0;
}
[type="submit"]:hover,
button:hover {
cursor: pointer;
}
[id="moins"],
[id="plus"] {
background: transparent;
border: 0;
width: 1.75rem;
height: 1.75rem;
top: 0.5875rem;
}
[id="moins"] {
left: 20%;
}
[id="plus"] {
right: 20%;
}
[id="fois"] {
background: transparent;
border: 0;
height: 1.25rem;
width: 1.25rem;
top: 3.75rem;
left: calc(50% - 0.625rem);
}
svg {
width: 100%;
height: 100%;
}
[id="moins"] svg,
[id="plus"] svg {
fill: #fff;
stroke: #fe9566;
}
[id="fois"] svg {
fill: #fe9566;
stroke: #fff;
}
[type="submit"] {
height: 3rem;
line-height: 3rem;
text-transform: uppercase;
width: calc(100% - 2rem);
margin: 0;
top: 0;
left: 1rem;
border: 0.125rem solid #fe9566;
border-radius: 1.5rem;
color: #fe9566;
background: #fff;
box-shadow: 0 0.25rem 0.125rem #e0e0e0;
}
#num {
position: absolute;
top: 0;
left: calc(50% - 1.5rem);
width: 3rem;
height: 3rem;
line-height: 3rem;
border-radius: 1.5rem;
background: #fe9566;
color: #fff;
border: 0;
box-shadow: 0 0.25rem 0.125rem #e0e0e0;
overflow: hidden;
}
#innum {
position:...
JavaScript
var num = 1;
function doReserve() {
document.querySelector('fieldset:first-of-type').style.top = "5rem";
document.querySelector('fieldset:last-of-type').style.top = "0";
}
function doLess() {
num--;
if (num < 1) num = 1;
document.querySelector('[id="innum"]').style.top = (-(num - 1) * 3) + "rem";
document.querySelector('[name="num"]').value = num + "";
}
function doMore() {
num++;
if (!document.querySelector('[id="innum"] span:nth-of-type(' + num + ')')) {
let e;
e = document.createElement("span");
e.innerHTML = num + "";
document.querySelector('[id="innum"]').appendChild(e);
}
document.querySelector('[id="innum"]').style.top = (-(num - 1) * 3) + "rem";
document.querySelector('[name="num"]').value = num + "";
}