is there a way to make my code run smoother and more efficient?
var headerH = $("#header").height();
var winH = $(window).height();
var newH = winH - headerH;
$("#wrap").css({ 'height' : newH + 'px' });
$(window).resize(function() {
var _headerH = $("#header").height();
var _winH = $(window).height();
var _newH = _winH - _headerH;
$("#wrap").css({ 'height' : _newH + 'px' });
});
//--Expand Panel
$(".open-menu").live('click', function(){
$("#wrap").css({ 'height' : newH + 'px' });
$(".mini-menu").fadeOut(500);
$("#headerCompany").animate({
marginLeft: '+=142'
}, 650);
$("#avatar_box").fadeIn(650);
$("#pinboard").fadeIn(550);
$("div#centerHeader").slideDown("slow");
$("#toggle-pinboard a").removeClass("open-menu").addClass("close-menu");
return false;
});
// Collapse Panel
$(".close-menu").live('click', function(){
$("#wrap").css({ 'height' : newH + 'px' });
$("#avatar_box").fadeOut(550);
$("#pinboard").fadeOut(550);
$("#headerCompany").animate({
marginLeft: '-=142'
}, 650);
$("div#centerHeader").slideUp(750).delay(300);
$.post('resources/ajax/ajax.php', {
action: 'mini_menu'
}, function(menu){
$("#mini-menu").hide().html(menu).addClass("mini-menu").fadeIn(1500);
});
$("#toggle-pinboard a").removeClass("close-menu").addClass("open-menu");
return false;
});
Another way to get rid of the 'live' is to do something like this:
$("#toggle-pinboard a").click(function() {
if ($(this).hasClass('open-menu')) {
// close menu code
}
else {
// open menu code
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.