I've got two huge scripts that are basically duplicates with only minor differences. They run the same exact animations and commands, but one function applies to a set of images. the second to the text navigation. I've been trying to figure out how to combine these into one, and they stop working, or half stops working. Maybe somebody can show me what it would look like if I combine these.
Basically, I want to combine the two bottom segments.
$('.square-container').on('click', '.square', function(event) {
if ( $(this).hasClass('active') ) { /* and so on */
and
$('.main-nav,.reg3,.privacy_policy,.subnav').on('click', '.main', function(event) {
if ( $(this).hasClass('aa') ) { /* and so on */
Here's the idea of what failed attempt:
$('.square-container','.main-nav,.reg3,.privacy_policy,.subnav').on('click', '.square' || '.main', function(event) {
if ( $(this).hasClass('active') || $(this).hasClass('aa') ) { /* and so on */
Here's a stripped down version of my starting point:
$(document).ready(function(){
$('.square-container').on('click', '.square', function(event) {
if ( $(this).hasClass('active') ) {
/* several animations here to return to start */
} else if ( $(this).hasClass('one') ) {
/* several animations for section 1 */
$('.one').addClass("subbed").stop().animate({ width: '227', height: '320', left: '260', top: '26', opacity: 1}, 600, function() {
/*load content*/;
});
/*Position unselected squares*/
/*Select active square*/
$('.square').removeClass('active');
$(this).addClass('active');
} else if {
/* several other else if statements to section 2, 3, 4 etc., then finish */
} else {
alert('nothing');
}
});
/* want to combine the above with below ... */
$('.main-nav,.reg3,.privacy_policy,.subnav').on('click', '.main', function(event) {
if ( $(this).hasClass('aa') ) {
/* several animations here to return to start */
} else if ( $(this).hasClass('ee') ) {
/* several animations for section 1 */
$('.one').addClass("subbed").stop().animate({ width: '227', height: '320', left: '260', top: '26', opacity: 1}, 600, function() {
/*load content*/;
});
/*Position unselected squares*/
/*Select active square*/
$('.square').removeClass('active');
$(this).addClass('active');
}
else {
alert('nothing');
}
});
};