If I were to embed a YouTube video for example
Pretty old question but if somebody still seeking for the answer, this one could be a better approach.
function getRelativeWidth(ratio, crntHght) { ratio = ratio.split(":"); var wdthRto = ratio[0]; var hghtRto = ratio[1]; return ((wdthRto*crntHght) / hghtRto); } function getRelativeHeight(ratio, crntWdth) { ratio = ratio.split(":"); var wdthRto = ratio[0]; var hghtRto = ratio[1]; return ((crntWdth*hghtRto) / wdthRto); } var wdth = 1600; var hght = 900; var getHeight = getRelativeHeight("16:9", wdth); var getWeight = getRelativeWidth("16:9", hght); console.log(getHeight); console.log(getWeight);