Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add form #4

Merged
merged 1 commit into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

[Small package](https://bundlephobia.com/result?p=calc-aspect-ratio) for calculating aspect ratio of display resolution.

## [Demo](https://vvideo.github.io/calc-aspect-ratio/example/index.html)
## Demo
- [Aspect ratio for your screen]](https://vvideo.github.io/calc-aspect-ratio/example/index.html)
- [Calculate aspect ratio]](https://vvideo.github.io/calc-aspect-ratio/example/form.html)


## Install
`npm i --save-dev calc-aspect-ratio`
Expand Down
73 changes: 73 additions & 0 deletions example/form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<!DOCTYPE html>
<html>
<head>
<title>Calc Aspect Ratio</title>
<meta charset="utf-8" />
<style>
html, body {
padding: 0;
margin: 0;
border: 0;
background: black;
color: white;
}

.form {
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
font-size: 16px;
}

.form__title {
font-size: 20px;
margin-bottom: 5px;
}

.form__item {
margin-top: 1em;
}
</style>
</head>
<body>
<div class="form">
<div class="form__title">Calculate aspect ratio</div>
<div class="form__item">
Width: <input id="width" type="number" value="1920" size="7" />
</div>
<div class="form__item">
Height: <input id="height" type="number" value="1080" size="7"/>
</div>
<div class="form__item">
Aspect ratio: <span class="form__result-value" id="result"></span>
</div>
</div>
<script type="module">
import { calcAspectRatio } from 'https://unpkg.com/calc-aspect-ratio/dist/index.esm.js';

const widthElem = document.querySelector('#width');
const heightElem = document.querySelector('#height');
const aspectRatioElem = document.querySelector('#result');

widthElem.oninput = updateText;
heightElem.oninput = updateText;

function updateText() {
const width = Number(widthElem.value);
const height = Number(heightElem.value);
let result = '-'

if (width && height) {
const aspectRatio = calcAspectRatio(widthElem.value, heightElem.value);
result = aspectRatio.value;
console.log(aspectRatio);
}

aspectRatioElem.innerHTML = result;
}

updateText();
</script>
</body>
</html>
Loading