// 累加計數器 function countUp(targetItem, animationTime, animationStep) { const targetNum = $(targetItem).text().split(',').join('') * 1 const addNumber = targetNum / (animationTime / animationStep) let returnNum = 0 function counter() { if(returnNum < targetNum) { returnNum = Math.ceil(returnNum + addNumber) setTimeout(counter, animationStep) } else { returnNum = targetNum } $(targetItem).text(addSeparator(returnNum)) } counter() } // 數字加上千分位 function addSeparator(string) { const numString = string * 1 + '' const floatAry = numString.split('.') const numAry = floatAry[0].split('') const remainderNum = numAry.length % 3 let kiloNum = '' for(let i = numAry.length - 1; i >= 0; i--) { kiloNum = numAry[i] + kiloNum if((i - remainderNum) % 3 === 0 && i !== 0) { kiloNum = ',' + kiloNum } } if(floatAry[1]) { kiloNum = kiloNum + '.' + floatAry[1] } return kiloNum } // 執行累加計數器 (function(window, document, $, jQuery) { $('.counterBox').each(function(i, item) { countUp(item, 1000, 25) }) })(window, document, $, jQuery); // 列表:查看更多公益活動 ;(function($, jQuery) { $('.timeline-wrapper').on('click', '.getMoreWelfare', function(e) { e.preventDefault() const itemsGroup = $(this).parents('.timeline-wrapper').find('.timeline-list > .item') const oldestYear = itemsGroup.eq(itemsGroup.length - 1).attr('data-year') const clickEle = $(this) jQuery.ajax({ url: '/welfare/ajax/ajax_get_welfare.php', type: 'POST', dataType: 'json', async: true, data: { 'year': oldestYear, }, }).done(function(res) { // console.log(res); // 沒有更多活動資訊時,隱藏「載入更多」按鈕 const findPrevId = (ele) => ele.prevID !== 0 if(!res.every(findPrevId)) { clickEle.addClass('hide') } else { clickEle.removeClass('hide') } const appendStr = res.reduce((prev, ele) => { return prev += `
${ele.date}