-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
55 lines (48 loc) · 1.5 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
$(document).ready(function () {
let width = document.querySelector("#width")
let height = document.querySelector("#height");
let image;
$("#photo").change(function (e) {
const reader = new FileReader();
reader.readAsDataURL(e.target.files[0]);
$(reader).on("load",() => {
changeImage(reader.result)
// console.log("Image Loaded")
})
});
function changeImage(imgURL){
image=new Image();
image.src=imgURL;
// console.log("changeImage called")
image.addEventListener("load",function(){
ratio = image.width/image.height;
width.value = image.width;
height.value = image.height;
})
}
$("#width").change(()=>{
if($("#keep").prop('checked') == true){
height.value=Math.floor(($("#width").val())/ratio);
}
})
$("#height").change(()=>{
if($("#keep").prop('checked') == true){
width.value = Math.floor($("#height").val()*(ratio));
}
})
$("#width").keyup(()=>{
if($("#keep").prop('checked') == true){
height.value=Math.floor(($("#width").val())/ratio);
}
})
$("#height").keyup(()=>{
if($("#keep").prop('checked') == true){
width.value = Math.floor($("#height").val()*(ratio));
}
})
$("#keep").click(()=>{
if($("#keep").prop('checked')==true){
height.value=Math.floor(($("#width").val())/ratio);
}
})
});