我在根據窗口寬度調整代碼時遇到了一些麻煩。如果窗口寬度小於450,我希望它滾動到某個部分,否則另一個。我哪裏錯了?jQuery窗口寬度條件不起作用
$('.artist-kina').click(function(e){
e.preventDefault();
$('html, body').animate({
if ($(window).width() < 450 {
scrollTop: $('#artists').offset().top - 60
}
else {
scrollTop: $('#artists').offset().top - 115
}
}, 500);
$('.artists-home').fadeOut(function() {
$('.kina-gallery').fadeIn('slow');
});
});
你已經忘記了一個括號你如果結構:'如果($(窗口).WIDTH())' – 2014-09-13 13:27:14
@ Pieter I把它放進去,現在我得到了一個意外的錯誤(''。這裏是錯誤:'錯誤在第148行第6列意外標記punc«(»,預計punc«:»' – J82 2014-09-13 13:30:41
^put 450後的parantesis如果($(window).width()<450){' – Arijoon 2014-09-13 13:33:43