Olá, estou criando uma barra de progresso e estou tendo problemas para executar corretamente o algoritmo.
Alguém pode me auxiliar ?
arquivo progress_bar.js
var reader;
var progress = document.querySelector('.percent');
function updateProgress(evt) {
// evt is an ProgressEvent.
if (evt.lengthComputable) {
var percentLoaded = Math.round((evt.loaded / evt.total) * 100);
// Increase the progress bar length.
if (percentLoaded < 100) {
progress.style.width = percentLoaded + '%';
progress.textContent = percentLoaded + '%';
}
}
}
function handleFileSelect(evt) {
// Reset progress indicator on new file selection.
progress.style.width = '0%';
progress.textContent = '0%';
reader = new FileReader();
reader.onprogress = updateProgress;
reader.onload = function(e) {
// Ensure that the progress bar displays 100% at the end.
progress.style.width = '100%';
progress.textContent = '100%';
setTimeout("document.getElementById('progress_bar').className='';", 2000);
};
// Read in the image file as a binary string.
reader.readAsDataURL(evt.target.files[0]);
}
Pergunta
willianeo
Olá, estou criando uma barra de progresso e estou tendo problemas para executar corretamente o algoritmo.
Alguém pode me auxiliar ?
arquivo progress_bar.js
var reader; var progress = document.querySelector('.percent'); function updateProgress(evt) { // evt is an ProgressEvent. if (evt.lengthComputable) { var percentLoaded = Math.round((evt.loaded / evt.total) * 100); // Increase the progress bar length. if (percentLoaded < 100) { progress.style.width = percentLoaded + '%'; progress.textContent = percentLoaded + '%'; } } } function handleFileSelect(evt) { // Reset progress indicator on new file selection. progress.style.width = '0%'; progress.textContent = '0%'; reader = new FileReader(); reader.onprogress = updateProgress; reader.onload = function(e) { // Ensure that the progress bar displays 100% at the end. progress.style.width = '100%'; progress.textContent = '100%'; setTimeout("document.getElementById('progress_bar').className='';", 2000); }; // Read in the image file as a binary string. reader.readAsDataURL(evt.target.files[0]); }pagina html
... <head> <script src="js/imput_file/progress_bar.js" type="text/javascript"></script> </head> ... <body> ... <div class="button_file"> <input type="file" id="files" name="image_one" class="file" multiple /> <!--<button onclick="abortRead();">Cancelar Upload</button>--> </div> ... <div class="button_file"> <input type="file" id="files" name="image_one" class="file" multiple /> </div> ... </body>Se ao invez de linkarr o arquivo js na página eu colocá-lo diretamente na página,
não tem problema algum.
Meu problema está em como linkar este programa no arquivo separadamente.
Link para o comentário
Compartilhar em outros sites
2 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.