1

Hey guys i am trying to make a slide in slide out on menu list items. And i am using transition to give an animation to css settings. Now the point is how can i do something using jquery after the css has been applied. i have written this code but it seems to work at the same time. I want is that the #homeContainer width should be 0px and then the #galleryContainer width starts to increase. thanks.

jQuery(document).ready(function($) {
$('#galleryListItem').click(function(){
    $('#homeContainer').css('width','0px');
    $('#galleryContainer').css('width','600px');
});});

2 Answers 2

1

You can use setTimeout function to put a delay (I used 500ms in the example below):

jQuery(document).ready(function($) {
$('#galleryListItem').click(function(){
    $('#homeContainer').css('width','0px');
    setTimeout(function () { $('#galleryContainer').css('width','600px'); }, 500);
});});
Sign up to request clarification or add additional context in comments.

Comments

0

You can use setTimeout for this to delay the application of css to the #galleryContainer, as suggested by malkassem, and you can also use setInterval to gradually increase the width(using an incrementing width value) of that container, to achieve the slide in effect, something along the lines of

var galleryWidth = 0;
setInterval(function () {
    galleryWidth += 50;
    $('#galleryContainer').css('width', galleryWidth + 'px');
}, 500);

But I think, in this case, what you really should use is jQuery's animate method (Reference). Like so:

$('#galleryListItem').click(function () {
    $('#homeContainer').animate({
        width: "0"
    }, 2000);
    $('#galleryContainer').show().animate({
        width: "600px"
    }, 2000);
});

Here's the DEMO

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.