Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

205
Visualizações
Wait until html text is replaced and loaded

I have a website that has a translate button. When the user clicks it, I use document.getElementsByClassName.innerHTML to change the language of all the html text.

However, I want my loading animation to show after the user clicks translate, until all the text has been replaced, and the language-specific font has loaded in as well.

How could I wait until this happens before turning off my loading animation visibility? As far as I understand, the DOM has already loaded when the user clicks translate.

Edit: I should've added some code initially. Here is a small sample of what I'm doing:

index.html

<div>
    <h1 class="1.1.1">My website</h1>
    <h1 class="1.1.2">Text sample 1</h1>
</div>

translate.js

function setEnglish() {
    document.getElementsByClassName("1.1.1")[0].innerHTML = "My website";
    document.getElementsByClassName("1.1.2")[0].innerHTML = "Text sample 1";
}
function setFrench() {
    document.getElementsByClassName("1.1.1")[0].innerHTML = "Mon site-web";
    document.getElementsByClassName("1.1.2")[0].innerHTML = "Exemple de texte 1";
}

There is a button in index.html that when pressed, calls a language toggle function (I'm only switching between two languages). I use simple logic to switch between the languages in translate.js.

So unfortunately, I have to repeat the English (main language) translation in the translate.js even though it exists in the html, because I need to toggle back to English from French.

I also have a font for the English translation and a font for the French translation that is changed in translate.js:

if language is English:

var body = document.getElementsByTagName('body')[0];
body.style.fontFamily = "font1";

if language is French:

var body = document.getElementsByTagName('body')[0];
body.style.fontFamily = "font2";

The problem is that when the user clicks the button, the text loads, but the font change is delayed, so the user sees the font change.

Currently, I have a loading animation that triggers every time the user clicks the translate button, but its set to last for a hard delay of 500ms (regardless of how quickly the font loads). After the time is up, the loading gif is hidden.

I want to delay the hiding of this loading animation until the font and text are done switching from the previous language, instead of having a constant delay. Sometimes, the loading animation expires, then the font changes because it hasn't loaded fast enough. Hope this clears things up.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda