Unsetting jQuery element manipulation automatically?
I am manipulating some elements with jquery when the doc is ready and when the window is resized, the problem is I dont want to have to specify to set everything back to normal when the condition does not apply. Here is my code:
function portfoliosingle_width(){
var window_width = $(window).width();开发者_Go百科
if(window_width < 964 ){
$('#portfolio-single #site-main .structure').width(450);
$('#portfolio-single #site-header').height(100);
$('#portfolio-single #site-header .structure').width(450);
$('#portfolio-single-text').width(425);
$('#portfolio-single-images').appendTo('.structure article');
$('#logo').css({'display':'block','width':'450px','float':'none'});
}else if(window_width > 964 ){
//want everything to go back the way it was without specifying each
}
}
$(document).ready(function(){
portfoliosingle_width();
});
$(window).bind("resize", function(){
portfoliosingle_width();
});
Is there a way to do this without consulting my stylesheet and looking up each value, setting each back to the way it originally was?
instead of specifying width / height in jquery, use css classes, do by adding a class and in else remove that class, it will return to normal
$("#myelement").addClass("structure450");
and then in else you can do
//when you remove the class it will return to normal width and height
$("#myelement").removeClass("structure450");
or you can set the width and height to "auto" in else.
after reading you comment, you can do something like this also.
//read the html in a variable
var orignalHTML = $("#parentDiv").html();
//in else use this html
else {
$("#parentDiv").html(orignalHTML);
}
You can set your element back to auto:
$('#theElement').css('height', 'auto');
精彩评论