$(function () { var $imageWrap = $(".event_wrap"); var $total = (".total") var alldata = []; var filterdata = []; $.getJSON("https://www.sekisuihouse.co.jp/event/cgi/api/1.3/eventlist.php?&callback=?", { siten: '350007', hits: '100', sortby: "entrydate|1" //cate: 'C0016,C0019,C0020,C0021,C0022,C0023,C0029,C0030,C0046,C0074' }, init); function init(data) { if (!data instanceof Array) { alert('invalid data'); return; } if (Object.keys(data).length === 0) { ($imageWrap).text('現在登録データがありません。'); } alldata = data; filterdata = alldata; display2(); }; //リスト表示 function display2() { $imageWrap.empty(); for (var i = 0; i < filterdata.length; i++) { //$('.total').html('

total:' + filterdata.length + '件

'); $( '
' + '' + '
' + '

' + filterdata[i].e_title + '

' + //'

' + filterdata[i].setumei.txt + '

' + '
' + '
' ).appendTo($imageWrap); $(document).ready(function () { $(".thumb").each(function () { var src = $(this).attr('src'); //console.log(src); if (src === 'null') { $(this).attr('src', '../images/dummy.jpg') } }); }); $(function () { const defaultDispCnt = 6; // 初期表示件数 const addDispCnt = 999; // 追加表示件数 let maxDispCnt = 0; // 最大表示件数 let currentDispCnt = 0; // 現在の表示件数 let tileList = $('.event_wrap').children('.box'); // 一覧のli子要素をすべて取得 setTimeout(function () { $('.event_wrap').stop().animate({ opacity: 1 }, { delay: 300, duration: 250 }); }, 150); // 一覧の初期表示 $(tileList).each(function (i, elem) { // 初期表示件数のみ表示 if (i < defaultDispCnt) { $(this).show().css("display", "block"); currentDispCnt++; } maxDispCnt++; // もっと見るボタンを表示 if (maxDispCnt >= currentDispCnt) { $('.readMoreBtn').show().css("display", "block"); } if (defaultDispCnt > currentDispCnt) { $('.readMoreBtn').hide(); $('#pagetop2 a').hide(); } }); if (defaultDispCnt > currentDispCnt) { $('#pagetop2 a').show().css("display", "block"); } // もっと見るボタンクリックイベント $('.readMoreBtn').click(function () { var newCount = currentDispCnt + addDispCnt; // 新しく表示する件数 // 新しく表示する件数のみ表示 $(tileList).each(function (i, elem) { if (currentDispCnt <= i && i < newCount) { $(this).show().css("display", "block"); currentDispCnt++; } }); // もっと見るボタンを非表示 if (maxDispCnt < newCount) { $(this).hide(); $('#pagetop2 a').show().css("display", "block"); } return false; }); }); } }; //ラジオボタンが変わった時にフィルタリングする $('#contents .event .bt_box a').on('click', function () { //チェックボタンの状況によってフィルタリングする var cate = $(this).attr('value'); $('#contents .event .bt_box a').removeClass('active'); $(this).addClass('active'); //フィルターの配列をいったん空っぽにする filterdata = []; if (cate === "all") { //allが選択されたら全データを保持 filterdata = alldata; } else { filterdata = $.grep(alldata, function (n) { return n.c_name.includes(cate); }); } display2(); if (Object.keys(filterdata).length === 0) { ($imageWrap).html('

現在登録データがありません。

'); $('.readMoreBtn').hide(); $('#pagetop a').hide(); } }); });