I have an element I am changing with an animation as follows:
that$.animate({
opacity:'0.0'
},300,
function() {
$('#menuHolder').css({
left:'0px',
top:'0px',
height:'100%',
width:'100%',
},0);
This is meant to make menuHolder take up the whole screen. When clicking a separate button, I want menuHolder to revert to the original values i assigned in the style sheet. Here is the code for the return button:
$('.return').bind('click',
function() {
$(this).hide(300);
tMT$ = $(this).parent();
tMT$.animate({
opacity:'0.0'
},300,
function() {
$('#menuHolder').css({
left:$(this).style.left,
top:$(this).style.top,
height:$(this).style.height,
width:$(this).style.width
},0);
})
This doesnt work, because I have assigned the original css values with when that$.animate was executed. How should I assign the values of .return's click so that menuHolder reverts to its original css?
I don't want to manually reassign values. I would rather do it programmatically =D. Any help would be great.
Cheers.
That is why you should not change individual CSS properties from your jQuery/Javascript code. Other than not being elegant, readable and maintainable and not separating presentation from behaviour, it will lead to situations like yours.
Instead:
Create classes in your CSS file:
.full-screen { left: 0; top: 0; width: 100%; height: 100%; }
and only use jQuery/Javascript to add/remove them:
$('#menuHolder').addClass('full-screen');
...
$('#menuHolder').removeClass('full-screen');
jQuery Class Manipulation Methods
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With