require(['config'], function () { require(['jquery', 'utils', 'swiper', 'pagination'], function ($, utils, Swiper, pagination) { $(function () { var TopGames = new Swiper('.swiper-container', { effect : 'fade', autoplay: { delay: 1000, disableOnInteraction:false }, loop: true, on: { transitionStart: function(){ var index = this.activeIndex - 1 if (this.activeIndex == 4) { $('.newsTopSwiper_r li').eq(0).addClass('active').siblings().removeClass('active') } else { $('.newsTopSwiper_r li').eq(index).addClass('active').siblings().removeClass('active') } }, } }); $('.newsTopSwiper_r li').hover(function () { var index = $(this).index() + 1 TopGames.slideTo(index, 300, false);//切换到第一个slide,速度为1秒 }) var navIndex = 0; // 0: 资讯 1:攻略 2:活动 var zx_index = 1; var gl_index = 1; var hd_index = 1; function chunk(array, size) { let [start, end, result] = [null, null, []]; for (let i = 0; i < Math.ceil(array.length / size); i++) { start = i * size; end = start + size; result.push(array.slice(start, end)); } return result; }; //导航切换 $('.newsBodyTitle li').on('click',function(){ navIndex = $(this).index(); $(this).addClass('active').siblings().removeClass('active'); $('.toggle_cnt>div').eq(navIndex).show().siblings().hide(); var total = 0; var number = 1; if (navIndex == 0) { total = zxArr.count; //资讯 number = zx_index; } else if (navIndex == 1) { total = glArr.count; //新闻 number = gl_index; } else if (navIndex == 2) { total = hdArr.count; //活动 number = hd_index; } // 生成分页并绑定分页事件 pagination({ elem : '#pagination', total : total, number : number, callback: renderGamelist }); }); // 页码 renderPagination(); function renderGamelist(page) { page = page || 1; var ajaxData; if (navIndex == 0) { zx_index = page; ajaxData = {'new_page': zx_index}; } else if (navIndex == 1) { gl_index = page; ajaxData = {'strategy_page': gl_index}; } else if (navIndex == 2) { hd_index = page; ajaxData = {'activity_page': hd_index}; } $.ajax({ url:'', data: ajaxData, type: 'get', success: function (res) { var resData = ''; if (navIndex == 0) { resData = res.news_list.new.list; $('.js-new_tpl').html(newsDatatoHtml(resData)) } else if (navIndex == 1) { resData = res.news_list.strategy.list; $('.js-strategy_tpl').html(newsDatatoHtml(resData)) } else if (navIndex == 2) { resData = res.news_list.activity.list; $('.js-activity_tpl').html(newsDatatoHtml(resData)) } } }) } function newsDatatoHtml(data) { var h = ''; $.each(data, function (i, v) { var date = new Date(v.pubdate * 1000) h += '\n' + '
  • \n' + '

    \n' + ' '+v.title+'\n' + '

    \n' + '
    \n' + '
    \n' + ' \n' + '
    \n' + '
    \n' + '

    '+v.post_content+'

    \n' + ' '+date.format("MM-dd hh:mm")+'\n' + '
    \n' + '
    \n' + '
  • \n' + '
    ' }); return h; } function renderPagination() { renderGamelist(); // 生成分页并绑定分页事件 pagination({ elem : '#pagination', total : zxArr.count, number : '', callback: renderGamelist }); } }) }) });