transition help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

transition help

property "transition: color .9 ease; " knocks down all other transition properties. and there are also options for optimizing the js code https://code.sololearn.com/W6SF12oDtQmE/?ref=app

2nd Dec 2022, 6:15 PM
Unreasonable
Unreasonable - avatar
9 Answers
+ 3
const Btns = document.querySelectorAll(".btn") const Sqrs = document.querySelectorAll(".square") window.onload = () => { Btns[0].addEventListener('click', () => { SetAtvs('red') }) Btns[1].addEventListener('click', () => { SetAtvs('green') }) Btns[2].addEventListener('click', () => { SetAtvs('yellow') }) Btns[3].addEventListener('click', () => { SetAtvs('blue') }) SetAtvs() } SetAtvs = (atv='') => { Btns.forEach((e) => { e.classList.remove('_active'); if (e.textContent == atv.toLowerCase()) e.classList.add('_active'); }); Sqrs.forEach((e) => { e.classList.remove('active'); if (e.textContent== atv.toUpperCase()) e.classList.add('active'); }); } https://code.sololearn.com/Wm64suaorJH2
3rd Dec 2022, 2:16 PM
SoloProg
SoloProg - avatar
+ 2
Unreasonable , Inside the "window.onload" block call the setatvs function and pick your desired color For example: SetAtvs('red')
3rd Dec 2022, 7:00 PM
SoloProg
SoloProg - avatar
+ 1
I moved your js to the bottom of the body of html. Apparently only the bottom transition definition will be used. You can combine the 3 effects by separating them with commas. https://code.sololearn.com/W9UJNTgdPeID/?ref=app
3rd Dec 2022, 11:37 AM
Lochard
Lochard - avatar
+ 1
Lochard , why did you move the js code to the body of html?
3rd Dec 2022, 12:46 PM
SUIII
SUIII - avatar
3rd Dec 2022, 1:00 PM
SoloProg
SoloProg - avatar
+ 1
SoloProg and how to make the first block initially open?
3rd Dec 2022, 6:47 PM
Unreasonable
Unreasonable - avatar
+ 1
SoloProg thank you very much
3rd Dec 2022, 7:07 PM
Unreasonable
Unreasonable - avatar
0
SoloProg and what if there are no keywords in the blocks, then what to refer to when switching?
8th Dec 2022, 10:28 PM
Unreasonable
Unreasonable - avatar
0
Unreasonable , When you call the function it will activate the keyword that it has.
9th Dec 2022, 1:36 PM
SoloProg
SoloProg - avatar