Last active
June 30, 2021 01:28
-
-
Save Uriel29/675faf3ca6e83c01e6ea to your computer and use it in GitHub Desktop.
Verificar dimensões de imagem antes do Upload com Jquery. O JS vê o tamanho das imagens antes do Upload, avisa o usuário e desabilita o botão submit!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Coloca a biblioteca Jquery no seu HTML. | |
jQuery("#img_principal").change(function() { //campo de imagem | |
var fr = new FileReader; | |
fr.onload = function() { | |
var img = new Image; | |
img.onload = function() { | |
if (img.width < 1400 && this.height < 800) { | |
jQuery('.aviso').append("<h2>Sua imagem é menor que 1400px de largura por 800px de altura </ br> use outra imagem</h2>"); | |
jQuery("#submit").attr("disabled", true); //Desabilita o botão sumbit | |
} else { | |
jQuery('.aviso').remove(); //remove a DIV aviso | |
jQuery('.aviso').append("<h3> Sua imagem tem as dimensões corretas</h3>"); //add outra mensagem | |
jQuery("#submit").removeAttr("disabled"); // Abilita o botão submit | |
} | |
}; | |
img.src = fr.result; | |
}; | |
fr.readAsDataURL(this.files[0]); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment