// 姝e紡鐗 const dataBaseUrl='https://cms.jingdiao.com' // 寮€鍙戠増 // const dataBaseUrl='http://localhost:1337' const token="1234f95023ab9af2112324d1940f005187b02fefbd4b9b2841904f28128450639ceb81c474a65dc14e754b83458d5604e0575a1b875c6519c64fbecd2b915ab9ad5b0420d37ad86980f2e8c54ab5daff8e211d59daf841786dd4a5a6a45f1bcf8002064802610cb8e8afbd39f5a03be2f251a521bdabc911f2affc73bb57b24e" jQuery(function($){ var cnc=[] var dating=[] var fms=[] var gold=[] var high_speed=[] var know=[] var more=[] getData() function getData(){ jQuery.ajax({ type: "GET", url: `${dataBaseUrl}/api/zh-videos?sort[0]=description:desc&sort[1]=id&populate[video]=*&populate[videoPoster]=*&pagination[pageSize]=500`, beforeSend: function(request) { request.setRequestHeader("Authorization",`Bearer ${token}`) }, success: function(result) { (result.data||[]).forEach(element => { let videoItem={ id: element.id, video_content: element.attributes.videoLink||`${dataBaseUrl}${element.attributes.video.data&&element.attributes.video.data.attributes.url}`, video_poster: element.attributes.videoPosterLink||`${dataBaseUrl}${element.attributes.videoPoster.data&&element.attributes.videoPoster.data.attributes.url}`, video_title:element.attributes.title, video_desc:element.attributes.description } if(element.attributes.category==='MoreVideo'){ more.push(videoItem) } else if(element.attributes.category==='InstantUnderstandingJingdiao'){ know.push(videoItem) } else if(element.attributes.category==='JingdiaoHaveAnAppointment'){ dating.push(videoItem) } else if(element.attributes.category==='TheBeautyOfGoldCut'){ gold.push(videoItem) } else if(element.attributes.category==='JingdiaoMachinePlusAutomationSolutions'){ fms.push(videoItem) } else if(element.attributes.category==='JingdiaoCNCMachiningCenter'){ cnc.push(videoItem) } else if(element.attributes.category==='JingdiaoHigh-speedMachiningCenter'){ high_speed.push(videoItem) } }) init() } }) } function init(){ new Swiper('.download-navs-container', { slidesPerView : 'auto' }) $('.download-navs-container .swiper-slide').click(function() { var id = '#' + $(this).attr('data-to') var top = $(id).offset().top var navHeight = $('#navs').innerHeight() $(this).siblings().removeClass('active') $(this).addClass('active') $('body, html').animate({ scrollTop: top-navHeight-47 }, 1000) }) navsFixed() $(window).scroll(function(){ navsFixed() var scrollTop = $(this).scrollTop(); var windowHeight = $(this).height()/2; if($("#high-speed").offset().top - windowHeight < scrollTop && $("#cnc").offset().top - windowHeight > scrollTop) { $('.download-navs-container .swiper-slide').removeClass('active') $('.download-navs-container .swiper-slide[data-to=high-speed]').addClass('active') } else if($("#cnc").offset().top - windowHeight < scrollTop && $("#fms").offset().top - windowHeight > scrollTop) { $('.download-navs-container .swiper-slide').removeClass('active') $('.download-navs-container .swiper-slide[data-to=cnc]').addClass('active') } else if($("#fms").offset().top - windowHeight < scrollTop && $("#gold").offset().top - windowHeight > scrollTop) { $('.download-navs-container .swiper-slide').removeClass('active') $('.download-navs-container .swiper-slide[data-to=fms]').addClass('active') } else if($("#gold").offset().top - windowHeight < scrollTop && $("#dating").offset().top - windowHeight > scrollTop) { $('.download-navs-container .swiper-slide').removeClass('active') $('.download-navs-container .swiper-slide[data-to=gold]').addClass('active') } else if($("#dating").offset().top - windowHeight < scrollTop && $("#know").offset().top - windowHeight > scrollTop) { $('.download-navs-container .swiper-slide').removeClass('active') $('.download-navs-container .swiper-slide[data-to=dating]').addClass('active') } else if($("#know").offset().top - windowHeight < scrollTop && $("#more").offset().top - windowHeight > scrollTop) { $('.download-navs-container .swiper-slide').removeClass('active') $('.download-navs-container .swiper-slide[data-to=know]').addClass('active') } else if($("#more").offset().top - windowHeight < scrollTop) { $('.download-navs-container .swiper-slide').removeClass('active') $('.download-navs-container .swiper-slide[data-to=more]').addClass('active') } }) initFirstPage() setTimeout(()=>{ var scrolltoIndex=window.location.search.search("scrollto"); if(scrolltoIndex!=-1){ var scrollto=window.location.search.substr(scrolltoIndex+9,15); console.log($(`.download-navs-container .swiper-slide[data-to='${scrollto}']`)[0]) $(`.download-navs-container .swiper-slide[data-to='${scrollto}']`).trigger('click') } },1000) } function navsFixed() { if($(document).width() <= 1024) { var pageNavHeight = 47; } else { var pageNavHeight = 60; } if($(document).scrollTop() > $('#navs').offset().top-pageNavHeight) { $('#navs').addClass('fixed'); $('.navs.tmp').css('display', 'block') } else if($(document).scrollTop() <= $('.part1').innerHeight()) { $('#navs').removeClass('fixed'); $('.navs.tmp').css('display', 'none') } } var nums = 3; //姣忛〉鍑虹幇鐨勬暟閲 var high_count = 1; var cnc_count = 1; var fms_count = 1; var gold_count = 1; var dating_count = 1; var know_count = 1; var more_count = 1; function downloadAdd (el, arr, page) { var total = arr.length; if(total==0) return; var pages = Math.ceil(total/nums); //寰楀埌鎬婚〉鏁 var str = '' var forTotal; if(page == pages) { forTotal = arr.length; } else { forTotal = page*nums; } for(var i = (page-1)*nums; i < forTotal; i++) { str += '
' + arr[i].video_title + '
' + '' + arr[i].video_desc + '
' + '