下午所有,
我有2块jQuery代码,有很多重复......我想知道是否有任何方法可以简化线条和/或性能.
2个街区如下:
$("#intro").css('min-height',$(window).height()-88);
$("#trabalhos").css('min-height',$(window).height()-88);
$("#fotografia").css('min-height',$(window).height()-88);
$("#cv").css('min-height',$(window).height()-88);
$("#contactos").css('min-height',$(window).height()-88);
Run Code Online (Sandbox Code Playgroud)
和:
$('.portfolio').click(function(e){ e.preventDefault();$('html,body').animate({scrollTop: $('#portfolio').offset().top-88},'slow'); });
$('.cv').click(function(e){ e.preventDefault();$('html,body').animate({scrollTop: $('#cv').offset().top-88},'slow'); });
$('.trabalhos').click(function(e){ e.preventDefault();$('html,body').animate({scrollTop: $('#trabalhos').offset().top-88},'slow'); });
$('.fotografia').click(function(e){ e.preventDefault();$('html,body').animate({scrollTop: $('#fotografia').offset().top-88},'slow'); });
$('.contactos').click(function(e){ e.preventDefault();$('html,body').animate({scrollTop: $('#contactos').offset().top-88},'slow'); });
Run Code Online (Sandbox Code Playgroud)
您可以将选择器组合成单个语句,用逗号分隔它们.
$('#intro, #trabalhos, #fotografia, #cv, #contactos').css('min-height',$(window).height()-88);
Run Code Online (Sandbox Code Playgroud)