0

I'm trying to create slidingUp divs with variable 'top' heights, so that one div may slideUp 700px, while another (with less content) slidesUp only 400px. Currently, the divs all slideUp at the same height. There are no div height declarations in the css. My script:

$(document).ready(function(){          
            var oldHeight;  
    $('a.menubtn').click(function(){              
            var newHeight;
            if ($(this.id) == 'work') {
                  newHeight = 700;  
                  }
                  else { if ($(this.id) == 'services') {
                      newHeight = 400;
                  }
                  else { if ($(this.id) == 'about') {
                      newHeight = 400;
                  }
                  else {
                      newHeight = 300;
                  }
                  }
                  }

            if ($('.active').length > 0) {

                $('.active').removeClass('active').animate({'top': '+=' + oldHeight + 'px'}, '200');
                $('div#contents_'+ this.id).addClass('active').animate({'top': '-=' + newHeight + 'px'}, '200');
                oldHeight = newHeight;
                }
                else 
    $('div#contents_'+ this.id).addClass('active').animate({'top': '-=' + newHeight + 'px'}, '200');
                oldHeight = newHeight;
                }
    return(false);
    });               
})

TIA.

1 Answer 1

2

Your if statements are wrong.

This:

$(this.id) == 'work'  // here you're comparing a jQuery object to 'work'

should be:

this.id == 'work'     // here you're comparing the actual ID value to 'work'

It would be cleaner if you changed the structure of the if statements to be like this:

if (this.id == 'work') {
    newHeight = 700;  
} else if (this.id == 'services') {
    newHeight = 400;
} else if (this.id == 'about') {
    newHeight = 400;
} else {
    newHeight = 300;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.