Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
how to use ternary operator in jquery animate method when it is inside a chain?

based on a variable I want to give logic to .animate method in jquery. how can I do that?

my code:

 $('#' + id)
    .delay(shortIntervalTime)
    .animate({opacity: 'show'})
    .delay(longIntervalTime)
    .fadeOut(3000, function () {
      if (flag === true) {
        cycle1(nextId, false);
      } else {
        vdoList = insertIntoArray(vdoListTwo);
        console.log({ vdoList });
        addDisplay(firstAd, true, vdoList);
      }
    });

so if id === 'block3' I want to use .animate({opacity: 'show', bottom: '100px'}) and in other case I want to use .animate({opacity: 'show'})

how can I do this?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You want to conditionally pass the object to animate method. So simply do this as:

.animate(
    id === 'block3'
        ? { opacity: 'show', bottom: '100px' }
        : { opacity: 'show' },
)

You can achive with ternary operator as:

$('#' + id)
    .delay(shortIntervalTime)
    .animate(
        id === 'block3'
            ? { opacity: 'show', bottom: '100px' }
            : { opacity: 'show' },
    )
    .delay(longIntervalTime)
    .fadeOut(3000, function () {
        if (flag === true) {
            cycle1(nextId, false);
        } else {
            vdoList = insertIntoArray(vdoListTwo);
            console.log({ vdoList });
            addDisplay(firstAd, true, vdoList);
        }
    });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!