$(function(){ var show = window.innerWidth <= 900 ? 20 : 20; //最初に表示する件数 var contents = '.newsList1 li'; // 対象のlist $(contents + ':nth-child(n + ' + (show + 1) + ')').addClass('is-hidden'); // ウィンドウがリサイズされたときに表示するアイテムの数を再計算 $(window).resize(function() { var newShow = window.innerWidth <= 900 ? 20 : 20; var newNum = newShow === 20 ? 20 : 20; $(contents + ':nth-child(n + ' + (newShow + 1) + ')').addClass('is-hidden'); $(".newsListInnerBlock1").each(function () { var numItems = $(this).find('ul.newsList1 li').length; if(numItems <= newNum){ $('.more1').addClass('is-hidden'); }else{ $('.more1').removeClass('is-hidden'); } }); }); $('.more1').on('click', function () { $(contents + '.is-hidden').slideDown(300, function() { updateVisibility(); }).removeClass('is-hidden'); }); $('.close1-1').on('click', function () { $('.newsList1 li:nth-of-type(n + 21)').slideUp(400).addClass('is-hidden'); $(this).css('display','none'); $('.more1').removeClass('none'); $('html, body').animate({ scrollTop: $('#anc1').offset().top }, 400); }); $('.close1-2').on('click', function () { $('.newsList1 li:nth-of-type(n + 21)').slideUp(400).addClass('is-hidden'); $(this).css('display','none'); $('.more1').removeClass('none'); $('html, body').animate({ scrollTop: $('#anc1').offset().top }, 400); }); function updateVisibility() { if ($(contents + '.is-hidden').length == 0) { $('.more1').addClass('none'); $('.close1-1').css('display','block'); $('.close1-2').css('display','block'); } else { $('.more1').removeClass('none'); $('.close1').css('display','none'); $('.close1-2').css('display','none'); } } }); $(function(){ $(".newsListInnerBlock1").each(function () { var num = $(this).find('ul.newsList1 li').length; if(num <= (window.innerWidth <= 900 ? 20 : 20)){ $('.more1').addClass('is-hidden'); }else{ $('.more1').removeClass('is-hidden'); } }); }); $(window).resize(function() { var newNum = window.innerWidth <= 900 ? 20 : 20 $(".newsListInnerBlock1").each(function () { var numItems = $(this).find('ul.newsList1 li').length; if(numItems <= newNum){ $('.more1').addClass('is-hidden'); }else{ $('.more1').removeClass('is-hidden'); } }); }); // Year selector navigation (news index or specific year) $(function(){ var $year = $('#year'); if(!$year.length) return; var path = window.location.pathname.replace(/\\/g, '/'); var base = (function(p){ var exact = '/product/biz/business-navi/news'; var idx = p.indexOf(exact + '/'); if(idx !== -1) return p.substring(0, idx + exact.length); var genericIdx = p.indexOf('/news/'); if(genericIdx !== -1) return p.substring(0, genericIdx + '/news'.length); return '/product/biz/business-navi/news'; })(path); var m = path.match(/\/news\/(\d{4})\//); if(m && m[1]){ $year.val(m[1]); }else if(/\/news\/index\//.test(path)){ $year.val(''); } $year.on('change', function(){ var v = $(this).val(); var to = v ? (base + '/' + v + '/') : (base + '/index/'); window.location.href = to; }); });