Reputation: 1
The context of which I'm working with is here: http://jsfiddle.net/888egs94/1/
To achieve the following I've been using (what seems like) a hundred versions of
$('.two').click(function() {
if($('.two')){
$('.two').addClass("one");
$('.two').removeClass("two") }
}
But I know there must be a simpler way. I am completely new to jQuery as of today. Trying to generate something like a conveyor belt for a client.
User clicks on .two:
User clicks on .three:
User clicks on .one:
It's essentially a carousel but inheriting classes if that makes sense. Any help is greatly appreciated. I have the animation down, it's just getting the classes right and consistent (so that they're not overlapping or moving when they're not supposed to).
Upvotes: 0
Views: 51
Reputation: 2313
A lot is going on here:
if
statement is not checking for a true or false, it's simply selecting some elements. .two
is always yellow and always in the middle. So if I give another block the class of .two
it would just instantly update itself to be in that spot. You could fix this by using different classes to assign color. else
statement to check if the class is .one
which would indicate showing a modal instead of rotating blocks. All that being said, I believe this is what you're looking for. Hopefully you can learn from this example. http://jsfiddle.net/xph5dgto/1/
Upvotes: 2