CKTIS / CSS
hypot() — velikost vektorja CSS
`hypot()` vrne velikost vektorja iz enega ali več izračunov skladnega tipa.
Različica: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Sintaksa
hypot( <calc-sum># )hypot() vrne velikost vektorja iz enega ali več izračunov skladnega tipa.
hypot(30px, 40px) nastavi širino na 50px; hypot(30%, 40%) v vsebniku 200 px da 100px; enoargumentni hypot(-12px) da absolutno vrednost 12px. Neskladni hypot(10px, 1deg) vrne false.
Slovnica: hypot( <calc-sum># ).
Rezultat ustreza sqrt(A² + …) in ohrani skupni tip argumentov: števila, združljive dimenzije ali odstotke. Dolžine ni mogoče mešati s kotom. Ker funkcija neposredno sprejme dimenzije, je uporabna za diagonale in razdalje transformacij; en argument deluje kot absolutna vrednost, vsak neskončni argument pa da pozitivni infinity.
Primeri
const host=document.createElement('div');host.style.cssText='width:200px;font-size:10px';document.body.append(host);
const used=value=>{const box=document.createElement('div');box.style.width=value;host.append(box);return getComputedStyle(box).width};
const triangle=used('hypot(30px, 40px)');
const percentage=used('hypot(30%, 40%)');
const absolute=used('hypot(-12px)');
const inconsistent=CSS.supports('width','hypot(10px, 1deg)');
console.log('triangle='+triangle+'; percentage='+percentage+'; single-negative='+absolute+'; inconsistent-types='+inconsistent);Rezultat
triangle=50px; percentage=100px; single-negative=12px; inconsistent-types=false
`hypot()` vrne velikost vektorja iz enega ali več izračunov skladnega tipa.