Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

jQuery Animation Problem

Hey everybody,

I'm a novice when it comes to coding with jQuery, but I was wondering if someone could steer me in the right direction. I'm trying to animate my divs, but show them once at a time, and by the click of a spacebar the user can see an animation like a pulse or flash and then prompt the next div. Anyways here's my code so far:

HTML

<div class="resume1"> 
  TEXT
</div>

<div class="resume2">
 Text
</div>

<div class="resume3">
  TEXT
</div>

<div class="resume4"> 
  TEXT 
</div>

CSS

.resume1, 
.resume2, 
.resume3, 
.resume4 {
  margin: 5px;
  border: 5px;
  background-color: #FDA3FB;
  border: 5px solid gray;
  padding: 10px;
}

jQuery

$('.resume2, .resume3, .resume4').hide(function(){
  $(this).keydown(function(e){
    $('.resume1').animate()
  });

});
//call anonymous function to animate div with cool
//effect
// on spacebar click switch to next div

2 Answers

Perhaps you could set a count variable and create a function that is called when the spacebar is pressed. Inside of the function you could concatenate the current count to the end of resume and make that the new selector (saved in a local variable). You could then use the show method to increment the count variable. The next time it is called, it would be the next div that becomes the selector. You would have to use a conditional statement to make sure the count wasn't larger than the amount of divs that you are showing or you will probably get an error. This is all theoretical, but I think that's how I would do it. Hopefully that made some sense. I may try this out if I have time. This is a link for finding the spacebar key event.

thanks Chris, I'm going to give it a try ill post what I come up with!