Home › Forums › JavaScript › Toggle Classes with delays
- This topic is empty.
-
AuthorPosts
-
December 7, 2014 at 9:35 am #190182RomchickParticipant
Hi there!
I have 4 blocks and I want script to add classes with a delay: appears 1 block, then 2nd and so on. here is the code:$(‘#about’).click(function() {
$(‘.front’).toggleClass(‘open-front’);
$(‘.back’).toggleClass(‘open-back’);
});And its important to have this two classes works together at the same time (smt like emulation of hover so to show @the back side of the block.
Got any ideas?
December 7, 2014 at 10:35 am #190191Paulie_DMemberJQ Functions like that happen in a row but they don’t wait for each one to finish before starting the next.
You add a delay and then tell the next funtion not to fire with
.queue()
December 7, 2014 at 10:37 am #190192Paulie_DMemberOr…you can use plain old JS and use
setTimeout
December 7, 2014 at 10:47 am #190193RomchickParticipantDecember 7, 2014 at 10:59 am #190195Paulie_DMemberSo start building….you have the building blocks there.
Images are no use at all.
Anyway, I don’t look at JS on live sites (and I don’t think many here would), use Codepen to make a simple demo with 4 simple divs, build the function and post the pen here for advice if you have any issues.
December 7, 2014 at 11:27 am #190200December 7, 2014 at 11:31 am #190201Paulie_DMemberDude….I’m not going to write it for you!
I gave you two examples of how it can be done….try figuring it out from there.
I did.
I have no skills with Js/JQ but a lot of trial and error and googling got me there….the best way to learn is to figure it out for yourself. Not have someone do your work for you.
December 7, 2014 at 11:38 am #190203RomchickParticipantI’ve been searching for the solution half of the day… thats why I’m here.
I have very poor exp with Js/JQ neither. So I’m asking it here to see maybe someone had similar expirience. I’ll keep on searching.December 7, 2014 at 12:03 pm #190208December 7, 2014 at 12:38 pm #190216Paulie_DMemberSee how easy that was?
Less than 30 minutes later you’ve found and answer.
December 7, 2014 at 12:40 pm #190217RomchickParticipantCuz I’ve stopped searching and asked it! 8)
December 7, 2014 at 1:24 pm #190221Paulie_DMember…and what did you learn?
Do you even understand the result?
December 7, 2014 at 1:35 pm #190222RomchickParticipantWeird, but yes.
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.