47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
function randomInt(min, max) {
|
|
return Math.floor(Math.random() * (max - min)) + min;
|
|
}
|
|
|
|
let titles = document.getElementsByClassName('variable-title');
|
|
|
|
for (const txt of titles) {
|
|
console.log(txt.innerText, '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -');
|
|
let splitted = Splitting({ target: txt, by: 'chars'});
|
|
console.log("splitted", splitted);
|
|
|
|
for (const word of splitted[0].words) {
|
|
let chars = word.getElementsByClassName('char');
|
|
|
|
for (const char of chars) {
|
|
|
|
console.log(char.innerText);
|
|
|
|
// Weight
|
|
let wght = randomInt(150, 600);//200 + Math.random() * 800;
|
|
|
|
// Width
|
|
let min_wdth = wght < 200 ? 50 : 10;
|
|
let max_wdth = wght > 500 ? 80 : 100;
|
|
let wdth = randomInt(min_wdth,max_wdth);//10 + Math.random() * 100;
|
|
|
|
// Ital
|
|
let ital = Math.random() > 0.7 ? 1 : 0;
|
|
char.style.fontVariationSettings = `'wght' ${wght}, 'wdth' ${wdth}, 'ital' ${ital}`;
|
|
|
|
// Letter spacing
|
|
let wdth_wght_ratio = wdth*wght / 10000;
|
|
console.log('wdth_wght_ratio',wdth_wght_ratio);
|
|
|
|
// char.style.letterSpacing = wdth_wght_ratio < 1 ? "0.5em" : ital ? "0.05em" : 0;
|
|
if (ital) {
|
|
let prev_char = char.previousSibling;
|
|
if (prev_char) {
|
|
char.style.letterSpacing = prev_char.style.letterSpacing = "0.03em";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
} |