1

Have this CSS code:

 <style>
.odometer{font-size: 180px; line-height: 100px;}
.odometer.odometer-auto-theme.odometer-animating-up .odometer-ribbon-inner,
.odometer.odometer-theme-minimal.odometer-animating-up .odometer-ribbon-inner,
.odometer.odometer-auto-theme.odometer-animating-down.odometer-animating .odometer-ribbon-inner,
.odometer.odometer-theme-minimal.odometer-animating-down.odometer-animating .odometer-ribbon-inner
{transition-duration: 3s !important}
</style>

Need to change the transition-duration on runtime, and of course, keep the !important flag.

Read many articles here with code examples, but couldn't get any one of them to work, maybe b/c of the nested CSS class structure.

appreciate the tip !

2
  • Would be a perfect job for CSS variables if you are ok using a polyfill for older browsers... Commented Sep 5, 2018 at 1:37
  • Whoever wrote that CSS should not be allowed anywhere near a computer. Commented Sep 5, 2018 at 2:08

2 Answers 2

1

Using jQuery you can update css properties using the .css function. You can then set a variable to any time you like to change the transition timing:

 var transitionTime = 5s;

 $('.odometer.odometer-auto-theme.odometer-animating-up .odometer-ribbon-inner,
    .odometer.odometer-theme-minimal.odometer-animating-up .odometer-ribbon-inner,
    .odometer.odometer-auto-theme.odometer-animating-down.odometer-animating .odometer-ribbon-inner, .odometer.odometer-theme-minimal.odometer-animating-down.odometer-animating .odometer-ribbon-inner'
 ).css('transition-duration', transitionTime + 's !important')
Sign up to request clarification or add additional context in comments.

7 Comments

But why using jQuery for this basic issue ?
@ths because it's easy to use and I'm guessing that avner is new to coding, if you have a vanilla JS solution please add it :)
Yes no doubt jQuery is easier. But to load the hole library for this task is an issue itself. Speed matters sometimes.
yep totally agree, personally I stopped using jQuery almost entirely since learning Vanilla JS and React. But when I started coding Vanilla JS was daunting and jQuery was easier to grasp. Worrying about optimization and speed is something that is more of a concern for middle-weight & senior devs
Any developer should worry about speed and optimisation. Did you see what happens behind the scene of jQuery's syntax ? We should worry about optimisation. Thanks for your time !
|
1

you can use document.querySelectorAll(".class1, .class2, class3");, then you can iterate over the nodeList

const nodeList = document.querySelectorAll(".class1, .class2, class3");

nodeList.forEach((el)=>{ el.style.transitionDuration = '5s' })

2 Comments

el.style.transitionTime doesn't exist. You probably meant el.style.transitionDuration.
awesome solution, tiny thing but you might have to add !important to the string since that's in the CSS

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.