I've got a number of divs (CSS class 'group'), and when one is clicked in, the others are hidden and the clicked on one is expanded (gaining the 'detailed' CSS class). Then, when the expanded div ('.group .detailed) is clicked on, it should resize and lose the 'detailed' class. My problem is, I can't get click events on 'group' divs that also contain 'detailed' to be ignored by my first jquery function and activate my second jquery function. Here's my code:
$('.group:not(.detailed)').mousedown(function(){
var $self = $(this);
var speed = 3250;
var offset = {x : $self.offset().left, y : $self.offset().top};
readyAnimation();
$('.group').not($self).addClass('hide');
$self.animate({'width' : '100%', 'height' : '+=' + '300px'}, {left: 'offset.x' + 'px', top: 'offset.y' + 'px'}, speed);
function readyAnimation () {
$self.css({display : 'block'});
$self.css({'-webkit-box-sizing' : 'border-box', '-moz-box-sizing' : 'border-box', 'box-sizing' : 'border-box'});
$self.css({margin : '0px'});
};
$self.addClass('detailed');
});
$('.group.detailed').mousedown(function(){
var $self = $(this);
var size = '300px';
var speed = 3250;
console.log("it worked");
resetAnimation();
$self.animate({'width' : size, 'height' : size}, speed)
$('.group').removeClass('hide');
function resetAnimation () {
$self.css({display : ''}); //Empty quotes resets the CSS value to what it was originally (in the CSS file)
$self.css({'-webkit-box-sizing' : '', '-moz-box-sizing' : '', 'box-sizing' : ''});
$self.css({margin : ''});
};
$self.removeClass('detailed');
});
I don't think I need to post my HTML and CSS for this, but they can be seen here in a previous question I asked. Thanks for reading.
EDIT: Here's a link to the fiddle
EDIT 2: See vahapwns, Jonathan and giordanolima's answers for working demonstrations of the code. By combining the two functions togother and using an if statement checking for 'detailed', problems arising from the first function overriding the second are solved. Thanks everybody for your input.