$(window).load(function(){
footerAccordion(); // Display footer as accordion on mobile sizes
});
$(window).resize(function(){
footerAccordion(); // Display footer as accordion on mobile sizes
});
function footerAccordion() {
if (window.innerWidth < 601) { /* NOTE THIS... */
$('.col .mobslider').hide();
$('.col').find('h2').click(function() {
if (window.innerWidth < 601) {
$(this).parent().find('.mobslider').stop().slideToggle();
} else if (window.innerWidth > 600) { /* WHAT's THIS THAN FOR ? */
$('.col .mobslider').show();
}
});
} else if (window.innerWidth > 600) {
$('.col .mobslider').show();
}
}
有道理?
一種解決方案是:
var winIsSmall;
$(window).on('load resize', footerAccordion);
function footerAccordion() {
winIsSmall = window.innerWidth < 601;
$('.col .mobslider').toggle(!winIsSmall);
}
$('.col').find('h2').click(function() {
if(winIsSmall){
$(this).parent().find('.mobslider').stop().slideToggle();
}
});
我猜你應用'click'功能到'h2'元素多次調整,而這將導致錯誤。 –