Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reset changed css values

Tags:

jquery

css

I've got...

$("#menu_tl").click(function() {

    $('.page').fadeOut();
    $('.page').animate({
        "width":  "0px", 
        "height": "0px", 
        "top":    "50px", 
        "left":   "50px"
    });

    $('#page1').fadeIn();
    $('#page1').animate({
        "width":  "500px", 
        "height": "400px", 
        "top":    "-350px", 
        "left":   "-450px"
    }, 2000);
});

$("#menu_tr").click(function() {

    $('.page').fadeOut();
    $('.page').animate({
        "width":  "0px", 
        "height": "0px", 
        "top":    "50px", 
        "left":   "50px"
    });

    $('#page2').fadeIn();
    $('#page2').animate({
        "width":  "500px", 
        "height": "400px"
    }, 2000);
});

But I want to say that when the second function is clicked all altered css by the first one should be reset. This means that the following line is wrong:

$('.page').animate({
    "width":  "0px", 
    "height": "0px", 
    "top":    "50px", 
    "left":   "50px"
});

is wrong and should be replaced by a global reset. Hope this is clear enough...

like image 331
Aeonius Avatar asked Apr 30 '11 20:04

Aeonius


2 Answers

This

$('.page').css({"width":"", "height":"", "top": "", "left" : ""});

should do the magic for you.

like image 109
c-smile Avatar answered Nov 09 '22 06:11

c-smile


Store the initial css values you will be changing in a variable:

var $page = $('.page'),
    initialCss = {
        width:  $page.css('width'),
        height: $page.css('height'),

        // Could also be .css('top'), .css(left')
        // depends on your initial stylesheet
        top:    $page.position().top + 'px',
        left:   $page.position().left + 'px'
    };

$("#menu_tr").click(function(){

    $page.animate( initialCss, 2000 );

});
like image 3
hitautodestruct Avatar answered Nov 09 '22 06:11

hitautodestruct