/* --------------------------------------------- smooth scroll lazyload対応 --------------------------------------------- */ $(function(){ $('a[href^="#"]').click(function(e){ const href = $(this).attr('href'), target = $(href == '#' || href == '' ? 'html' : href), position = target.offset().top; $.when( $('html, body').animate({ scrollTop: position }, 500, 'swing'), e.preventDefault(), ).done(function(){ setTimeout(function(){ const diff = target.offset().top; if (diff === position){ } else { $('html, body').animate({ scrollTop: diff }, 300, 'swing'); } }, 300); }); }); }); /* --------------------------------------------- アンケート回答 --------------------------------------------- */ $(function(){ const question = $('.questionnaire .question'), input = $('.questionnaire .question input'), btn = $('.transitionBtn'); question.each(function(i) { const num1 = i + 1; $(this).find('input').attr('name','q' + num1); $(this).find('.afterSelect').addClass('afterSelect_qre' + num1); $(this).find('li').each(function(e) { const num2 = 'q' + num1 + '_' + (e + 1); $(this).find('input').attr({ 'id': num2, 'data-qre': 'qre' + num1 }); $(this).find('label').attr('for', num2); }); }); input.on('click',function() { const qre = $(this).data('qre'), elm = $('.afterSelect_' + qre); if (elm.length) { elm.addClass('active').slideDown(500); window.scroll({ top: elm.offset().top, behavior: 'smooth' }); } else { window.scroll({ top: $('.next_target_' + qre).offset().top, behavior: 'smooth' }); } const check = question.map(function() { return $(this).find('input:checked').length ? 'checked' : null; }).get(); if (check.filter(Boolean).length === question.length) { btn.addClass('active'); } else { btn.removeClass('active'); } }); }); /* --------------------------------------------- swiper --------------------------------------------- */ const swiper = new Swiper('.swiper-container', { slidesPerView: 1.25, centeredSlides: true, navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', } });