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

210
Visualizações
How can I put a condition on the way of jQuery chain?

I have this function:

function startBlinking(el, speed = 100) {
  el.css('display', 'inline').fadeToggle(speed, function() {
    startBlinking(el, speed)
  });
}

I want to add one more parameter to the function to make .css('display', 'inline') part conditional. Something like this:

function startBlinking(el, speed = 100, inlineDisplay = true) {

  if (inlineDisplay){
      el.css('display', 'inline').fadeToggle(speed, function() {
        startBlinking(el, speed)
      });
  } else {
      el.fadeToggle(speed, function() {
        startBlinking(el, speed)
      });
  }
}

But the new version looks ugly. I want to know is there any approach to add a condition in the chain?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Get the current display value and add a condition for inlineDisplay parameter. If inlineDisplay is false or undefined the current display value will persist else it will be inline.


function startBlinking(el, speed = 100, inlineDisplay = true) {
    const currentDisplay = el.css('display');
    el.css('display', inlineDisplay ? 'inline' : currentDisplay).fadeToggle(speed, function() {
        startBlinking(el, speed)
      });
}

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