[英]is there a way to make my jquery code more efficient?
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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.