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

230
Visualizações
Animación de título de JavaScript para pestaña inactiva

Encontré un script aquí para consultar la actividad de la pestaña del navegador y quería combinar eso con una función que reproduce una pequeña animación de título cuando está inactiva.

Aparte del hecho de que todavía puedo optimizar el rendimiento de alguna manera, se muestran símbolos de error en cada lado cuando el tren ha pasado una vez.

Al principio pensé que era el emoji (dos emoji combinados), pero a otros también les pasa. ¿Alguien tiene una idea?

 var vis = (function () { var stateKey, eventKey, keys = { hidden: "visibilitychange", webkitHidden: "webkitvisibilitychange", mozHidden: "mozvisibilitychange", msHidden: "msvisibilitychange" }; for (stateKey in keys) { if (stateKey in document) { eventKey = keys[stateKey]; break; } } return function (c) { if (c) { document.addEventListener(eventKey, c); //document.addEventListener("blur", c); //document.addEventListener("focus", c); } return !document[stateKey]; }; })(); var storeTitle = document.title, myAnimation; function getLokTitle() { let title = "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 🚂 ", //let title = "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 🚄 ", i = 0; myAnimation = setTimeout(function () { setInterval(function () { document.title = title.substr(i, title.length) + title.substr(0, i); i = (i + 1) % title.length; if (vis() === true) { clearTimeout(myAnimation); document.title = storeTitle; return storeTitle; } }, 250); }, 1000); return title; } function getStoreTitle() { if (typeof myAnimation !== "undefined") { clearTimeout(myAnimation); } return storeTitle; } vis(function () { document.title = vis() ? getStoreTitle() : getLokTitle(); //console.log(new Date, 'visible ?', vis()); }); // to set the initial state document.title = vis() ? getStoreTitle() : getLokTitle();
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Gracias a Niet el Absol Oscuro ,

aquí está el código final:

 // Source: https://stackoverflow.com/questions/19519535/detect-if-browser-tab-is-active-or-user-has-switched-away/19519701#19519701 // var visible = vis(); // vis(function(){}); var vis = (function () { var stateKey, eventKey, keys = { hidden: "visibilitychange", webkitHidden: "webkitvisibilitychange", mozHidden: "mozvisibilitychange", msHidden: "msvisibilitychange" }; for (stateKey in keys) { if (stateKey in document) { eventKey = keys[stateKey]; break; } } return function (c) { if (c) { document.addEventListener(eventKey, c); //document.addEventListener("blur", c); //document.addEventListener("focus", c); } return !document[stateKey]; }; })(); var storeTitle = document.title, myAnimation; function getLokTitle() { var title = "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 🚂 ", //let title = "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 🚄 ", i = 0; document.title = title; myAnimation = setTimeout(function () { let title = Array.from("_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 🚂 "); setInterval(function () { //document.title = title.substr(i, title.length) + title.substr(0, i); document.title = title.slice(i).concat(title.slice(0, i)).join(""); i = (i + 1) % title.length; if (vis() === true) { clearTimeout(myAnimation); document.title = storeTitle; return storeTitle; } }, 250); }, 1000); return title; } function getStoreTitle() { if (typeof myAnimation !== "undefined") { clearTimeout(myAnimation); } return storeTitle; } vis(function () { document.title = vis() ? getStoreTitle() : getLokTitle(); //console.log(new Date, 'visible ?', vis()); }); // to set the initial state document.title = vis() ? getStoreTitle() : getLokTitle();
about 4 years ago · Juan Pablo Isaza Relatório
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