"use strict"; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 兼容操作 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ if (XHOME.browser.browserVersion().browserType == 'isIE' && (XHOME.browser.browserVersion().ieType == 9 || XHOME.browser.browserVersion().ieType == 8)) { XHOME.browser.removeCss('../css/swiper.min.css'); XHOME.browser.removeScript('../js/swiper.min.js'); } if (XHOME.browser.browserVersion().browserType == 'isIE' && XHOME.browser.browserVersion().ieType == 10) { $('.breath').removeClass('breath'); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 通用功能设置 (轮播图 音频播放) * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / /* swiper 设置 */ function setSwiper(opts, callback, slideChange) { var defaultOpts = { swiperID: opts.swiperID || '.swiper-container', id: opts.id, loop: opts.loop || false, autoplay: opts.autoplay || 0, effect: opts.effect || 'slide', slidesPerView: opts.slidesPerView || 1, slidesPerGroup: opts.slidesPerGroup || 1, spaceBetween: opts.spaceBetween || 0, onSlideChangeEnd: slideChange, centeredSlides: opts.centeredSlides || false, speed: 1000, onInit: function onInit(swiper) {//Swiper初始化了 // // // console.log(opts.id, '初始化了'); } }; if (XHOME.browser.browserVersion().browserType == 'isIE' && XHOME.browser.browserVersion().ieType == 10) { defaultOpts.effect = 'slide'; } if (XHOME.browser.browserVersion().browserType == 'isIE' && (XHOME.browser.browserVersion().ieType == 9 || XHOME.browser.browserVersion().ieType == 8)) { defaultOpts.mode = opts.direction || 'horizontal'; if (opts.lazy) { XHOME.lazy.loading(defaultOpts.id); } } else { defaultOpts.direction = opts.direction || 'horizontal'; if (opts.lazy) { defaultOpts.lazyLoading = true; defaultOpts.lazyLoadingInPrevNext = true; defaultOpts.lazyLoadingInPrevNextAmount = 2; } if (opts.hasArrow) { defaultOpts.prevButton = opts.id + ' .swiper-button-prev'; defaultOpts.nextButton = opts.id + ' .swiper-button-next'; } } if (opts.hasPagination) { defaultOpts.pagination = opts.id + ' .swiper-pagination'; defaultOpts.paginationClickable = true; } if (opts.hasScrollbar && (XHOME.browser.browserVersion().browserType !== 'isIE' || XHOME.browser.browserVersion().browserType == 'isIE' && XHOME.browser.browserVersion().ieType == 11)) { defaultOpts.scrollbar = opts.id + ' .swiper-scrollbar'; defaultOpts.scrollbarHide = false; } var mySwiper = new Swiper(defaultOpts.id + ' ' + defaultOpts.swiperID, defaultOpts); if (XHOME.browser.browserVersion().browserType == 'isIE' && (XHOME.browser.browserVersion().ieType == 9 || XHOME.browser.browserVersion().ieType == 8)) { if (opts.hasArrow) { $(opts.id + ' .swiper-button-prev').on('click', function (e) { e.preventDefault(); mySwiper.swipePrev(); }); $(opts.id + ' .swiper-button-next').on('click', function (e) { e.preventDefault(); mySwiper.swipeNext(); }); } } callback && callback(mySwiper); } /* 关闭全媒体播放器 */ function closeAllMedia(id) { // 关闭视频播放 $(id).on('click', '.media-close', function () { XHOME.media.close(); IE11TipsHide(); }); } /* IE11 直播提示 */ function IE11TipsShow(id) { var u = window.navigator.userAgent.toLocaleLowerCase(), ie11 = /(trident)\/([\d.]+)/, b = u.match(ie11); // console.log(u); if (b) { $(id).removeClass('hide'); } } function IE11TipsHide(id) { $(id).addClass('hide'); } /* tab切换 */ function tabSwitch(opts) { var newOpts = { id: opts.id, clickedBtn: opts.clickedBtn ? opts.clickedBtn : '.tab-name-item', type: opts.type ? opts.type : 'mouseenter', // 点击还是滑过 effect: opts.effect ? opts.effect : 'fade', initIndex: opts.initIndex ? opts.initIndex : 0, callback: function callback(res) { var idx = res.index; var swichCont = opts.swichCont ? opts.swichCont : '.tab-cont-item'; $(opts.id).find(swichCont).eq(idx).addClass('active').siblings().removeClass('active'); } }; if (!newOpts.id) return; XHOME.tab.init({ selector: newOpts.id, // 选择器 可以是id 也可以是class clickedBtn: newOpts.clickedBtn, type: newOpts.type, // 点击还是滑过 effect: newOpts.effect, initIndex: newOpts.initIndex, swichCont: newOpts.swichCont, callback: newOpts.callback }); } /* 横向滚动 */ function marquee(id, width, duration) { var tl = gsap.timeline({ repeat: -1 }); tl.to(id, { x: -width / 2, duration: duration, ease: 'none' }); $(id).on('mouseenter', function () { tl.pause(); }); $(id).on('mouseleave', function () { tl.play(); }); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 习专区相关功能(大头条 习大图 习全媒体轮播图 小头条) * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / /* 大头条字号颜色设置 */ function setFontSize() { var fs = $.trim($('#headline').attr('data-fontsize')); var fc = $.trim($('#headline').attr('data-fontcolor')); if (fs != '') { $('#headline').find('h1').css({ 'font-size': fs + 'px' }); } if (fc != '') { $('#headline').find('h1').find('a').css({ color: fc }); $('#headline').find('p').find('a').css({ color: fc }); } } /* 习专区大图轮播 */ function xiBigImgsScroll() { // 启动swiper var swiperOpts = { id: '#xiBigImgsScroll', autoplay: 5000, hasPagination: true, loop: true, hasArrow: true }; setSwiper(swiperOpts); } /* 习专区全媒体播放器 */ function xiNewsMediaScroll() { var slideArticleNum = parseInt($.trim($('#xiNewsMediaScroll .scroll-articleNum').html())); var slideOriginArticleNum = parseInt($('#xiNewsMediaScroll').find('.scroll-articles').length); var videoList = []; var iframeList = []; var liveList = []; var initIndex = 0; // console.log('xiNewsMediaScroll:',slideArticleNum, slideOriginArticleNum); if (slideArticleNum < slideOriginArticleNum && slideArticleNum !== 0) { $('#xiNewsMediaScroll').find('.scroll-articles').each(function (index) { if (index >= slideArticleNum) { $(this).remove(); } }); } // 设置播放按钮和播放列表 $('#xiNewsMediaScroll').find('.swiper-slide').each(function (index) { var title = $(this).find('.tit').find('a').text(); var url = $(this).attr('data-url'); var poster = $(this).find('.img').find('img').attr('src'); if ($.trim(url) != '') { if (XHOME.browser.browserVersion().ieType != 9 && XHOME.browser.browserVersion().ieType != 10) { $(this).find('.img').find('a').removeAttr('href'); } $(this).find('.tit').find('.btn').removeClass('hide'); if (url.indexOf('.mp4') > -1) { videoList.push({ swiperIdx: index, title: title, url: url, poster: poster }); } if (url.indexOf('.m3u8') > -1 || url.indexOf('.flv') > -1) { liveList.push({ swiperIdx: index, title: title, url: url, poster: poster }); } if (url.indexOf('.html') > -1 || url.indexOf('.htm') > -1) { iframeList.push({ swiperIdx: index, title: title, url: url, poster: poster }); } } }); // 启动swiper var swiperOpts = { id: '#xiNewsMediaScroll', effect: 'fade', autoplay: 5000, hasPagination: true, hasArrow: true, loop: true, lazy: true }; setSwiper(swiperOpts, function (mySwiper) { $('#xiNewsMediaScroll').hover(function () { mySwiper.stopAutoplay(); }, function () { mySwiper.startAutoplay(); }); // 图片和播放按钮点击 播放视频 $('#xiNewsMediaScroll').on('click', '.img,.btn', function () { if (XHOME.browser.browserVersion().browserType == 'isIE' && (XHOME.browser.browserVersion().ieType == 9 || XHOME.browser.browserVersion().ieType == 10)) { return; } var selector = '#xiNewsMediaScroll'; var playList = videoList; var type = 'mp4'; var isOnLive = false; if ($(this).parents('.swiper-slide').attr('data-url').indexOf('.html') > -1 || $(this).parents('.swiper-slide').attr('data-url').indexOf('.htm') > -1) { playList = iframeList; type = 'iframe'; } if ($(this).parents('.swiper-slide').attr('data-url').indexOf('.m3u8') > -1 || $(this).parents('.swiper-slide').attr('data-url').indexOf('.flv') > -1) { playList = liveList; type = 'mp4'; isOnLive = true; } playList.filter(function (item, index) { if (item.swiperIdx === mySwiper.realIndex) { initIndex = index; XHOME.media.begin({ selector: selector, initIndex: initIndex, type: type, list: playList, isOnLive: isOnLive, callback: function callback(res) { XHOME.scroll.monitorLoc({ selector: res.selector, height: res.height, callback: function callback(res) { // // // console.log(res) var isFixed = true; if (res.location === 'windowTop' && res.status === 'show') { // 页面down 从顶部出现 isFixed = false; } if (res.location === 'windowTop' && res.status === 'hide') { // 页面up 从顶部消失 isFixed = true; } // // // console.log(isFixed) if (isFixed) { XHOME.media.setBoxSize({ selector: res.selector }); $('.media-title').css({ fontSize: '16px', lineHeight: '26px', height: '26px' }); } else { XHOME.media.clearBoxSize(); $('.media-title').css({ fontSize: '20px', lineHeight: '55px', height: '55px' }); } } }); } }); } }); }); }); } /* 习专区小头条 */ function xiNewsMediaListHover() { $('#xiNewsMediaList').on('mouseenter', 'li', function () { $(this).addClass('active').siblings().removeClass('active'); }); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 头屏区相关功能(全媒体轮播图 最新播报 小头条 授权发布 特稿 评论) * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / /* 头屏区小头条 */ function focusNewsMediaListHover() { $('#focusNewsMediaList').on('mouseenter', 'li', function () { $(this).addClass('active').siblings().removeClass('active'); }); } /* 头屏区全媒体播放器 */ function focusNewsMediaScroll() { var slideArticleNum = parseInt($.trim($('#focusNewsMediaScroll .scroll-articleNum').html())); var slideOriginArticleNum = parseInt($('#focusNewsMediaScroll').find('.scroll-articles').length); var videoList = []; var iframeList = []; var liveList = []; var initIndex = 0; // console.log('focusNewsMediaScroll:',slideArticleNum, slideOriginArticleNum); if (slideArticleNum < slideOriginArticleNum && slideArticleNum !== 0) { $('#focusNewsMediaScroll').find('.scroll-articles').each(function (index) { if (index >= slideArticleNum) { $(this).remove(); } }); } // 设置播放按钮和播放列表 $('#focusNewsMediaScroll').find('.swiper-slide').each(function (index) { var title = $(this).find('.tit').find('a').text(); var url = $(this).attr('data-url'); var poster = $(this).find('.img').find('img').attr('src'); if ($.trim(url) != '') { if (XHOME.browser.browserVersion().ieType != 9 && XHOME.browser.browserVersion().ieType != 10) { $(this).find('.img').find('a').removeAttr('href'); } $(this).find('.tit').find('.btn').removeClass('hide'); if (url.indexOf('.mp4') > -1) { videoList.push({ swiperIdx: index, title: title, url: url, poster: poster }); } if (url.indexOf('.m3u8') > -1 || url.indexOf('.flv') > -1) { liveList.push({ swiperIdx: index, title: title, url: url, poster: poster }); } if (url.indexOf('.html') > -1 || url.indexOf('.htm') > -1) { iframeList.push({ swiperIdx: index, title: title, url: url, poster: poster }); } } }); // 启动swiper var swiperOpts = { id: '#focusNewsMediaScroll', effect: 'fade', autoplay: 5000, hasPagination: true, hasArrow: true, loop: true, lazy: true }; setSwiper(swiperOpts, function (mySwiper) { $('#focusNewsMediaScroll').hover(function () { mySwiper.stopAutoplay(); }, function () { mySwiper.startAutoplay(); }); // 图片和播放按钮点击 播放视频 $('#focusNewsMediaScroll').on('click', '.img,.btn', function () { if (XHOME.browser.browserVersion().browserType == 'isIE' && (XHOME.browser.browserVersion().ieType == 9 || XHOME.browser.browserVersion().ieType == 10)) { return; } var selector = '#focusNewsMediaScroll'; var playList = videoList; var type = 'mp4'; var isOnLive = false; if ($(this).parents('.swiper-slide').attr('data-url').indexOf('.html') > -1 || $(this).parents('.swiper-slide').attr('data-url').indexOf('.htm') > -1) { playList = iframeList; type = 'iframe'; } if ($(this).parents('.swiper-slide').attr('data-url').indexOf('.m3u8') > -1 || $(this).parents('.swiper-slide').attr('data-url').indexOf('.flv') > -1) { playList = liveList; type = 'mp4'; isOnLive = true; } playList.filter(function (item, index) { if (item.swiperIdx === mySwiper.realIndex) { initIndex = index; XHOME.media.begin({ selector: selector, initIndex: initIndex, type: type, list: playList, isOnLive: isOnLive, callback: function callback(res) { XHOME.scroll.monitorLoc({ selector: res.selector, height: res.height, callback: function callback(res) { // // // console.log(res) var isFixed = true; if (res.location === 'windowTop' && res.status === 'show') { // 页面down 从顶部出现 isFixed = false; } if (res.location === 'windowTop' && res.status === 'hide') { // 页面up 从顶部消失 isFixed = true; } // // // console.log(isFixed) if (isFixed) { XHOME.media.setBoxSize({ selector: res.selector }); } else { XHOME.media.clearBoxSize(); } } }); } }); } }); }); }); } /* 头屏区产品 */ function focusNewsMediaProducts() { // 设置播放按钮和播放列表 $('#focusNewsMediaProducts').find('li').each(function (index) { var url = $(this).attr('data-url'); if ($.trim(url) != '') { $(this).find('.btn').removeClass('hide'); } }); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 主体区域相关功能(现场直击 融媒视角 高清影像 代表之声) * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ function onsiteDefaultActive() { var defaultIdx = $('#onsite').find('.tab-name').find('.active').length ? $('#onsite').find('.tab-name').find('.active').index() : 0; console.log(defaultIdx); $('#onsite').find('.tab-name').find('.tab-name-item').eq(defaultIdx).addClass('active'); $('#onsite').find('.tab-cont').find('.tab-cont-item').eq(defaultIdx).addClass('active'); } function hdphotosScroll() { // 启动swiper var swiperOpts = { id: '#hdphotos', effect: 'fade', autoplay: 5000, hasPagination: true, hasArrow: true, loop: true, lazy: true }; setSwiper(swiperOpts, function (mySwiper) { $('#hdphotos').hover(function () { mySwiper.stopAutoplay(); }, function () { mySwiper.startAutoplay(); }); }); } function representativeScroll() { // 启动swiper var swiperOpts = { id: '#representative', // effect: 'fade', autoplay: 5000, hasPagination: false, hasArrow: true, loop: true, lazy: true, slidesPerView: 2, spaceBetween: 45 }; setSwiper(swiperOpts, function (mySwiper) { $('#representative').hover(function () { mySwiper.stopAutoplay(); }, function () { mySwiper.startAutoplay(); }); }); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 底部区域相关功能(图解海报 光辉十年 多语报道) * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ function posterScroll() { // 启动swiper var swiperOpts = { id: '#poster', autoplay: 5000, // hasScrollbar: true, hasArrow: true, hasPagination: true, loop: true, lazy: true, slidesPerView: 3, spaceBetween: 25 }; setSwiper(swiperOpts, function (mySwiper) { $('#poster').hover(function () { mySwiper.stopAutoplay(); }, function () { mySwiper.startAutoplay(); }); }); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 右侧固定导航 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ function toTop() { $('#totop').on('click', function () { XHOME.scroll.toTop(); }); } function closeFixedNav() { $('#fixedNavClose').on('click', function () { $('#fixedNav').remove(); }); } function hideFixedNav() { if ($(window).width() >= 1600) { $('#fixedNav').removeClass('alwaysHide'); } else { $('#fixedNav').addClass('alwaysHide'); } } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 延迟加载及滚动监听 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ function addTopPart() { XHOME.lazy.loading('#focus'); /* 头屏区 */ focusNewsMediaListHover(); //小头条鼠标滑过 focusNewsMediaScroll(); //全媒体播放器 closeAllMedia('#focusNewsMediaScroll'); //关闭全媒体播放器 focusNewsMediaProducts(); //产品区是否显示播放按钮 tabSwitch({ id: '#comment' }); } function addCenterPart() { XHOME.lazy.loading('#main'); /* 主体区 */ onsiteDefaultActive(); tabSwitch({ id: '#onsite' }); hdphotosScroll(); representativeScroll(); } function addBottomPart() { XHOME.lazy.loading('#bottom'); /* 底部区 */ posterScroll(); $('#languagesIframe').find('iframe').attr('src', $('#languagesIframe').find('iframe').attr('data-src')); } var productIsFirstLoad = true; var mainIsFirstLoad = true; var bottomIsFirstLoad = true; $(function () { tabSwitch({ id: '#leadersTabOutside', type: 'click', clickedBtn: '.tab-outside-name-item', swichCont: '.tab-outside-cont-item' }); tabSwitch({ id: '#leadersTabInside0', type: 'click', clickedBtn: '.tab-inside-name-item', swichCont: '.tab-inside-cont-item' }); tabSwitch({ id: '#leadersTabInside1', type: 'click', clickedBtn: '.tab-inside-name-item', swichCont: '.tab-inside-cont-item' }); tabSwitch({ id: '#leadersTabInside2', type: 'click', clickedBtn: '.tab-inside-name-item', swichCont: '.tab-inside-cont-item' }); /* 习专区 */ setFontSize(); //习专区大头条 xiBigImgsScroll(); //习专区大图轮播 xiNewsMediaScroll(); //习专区全媒体播放器 closeAllMedia('#xiNewsMediaScroll'); //关闭全媒体播放器 xiNewsMediaListHover(); //习专区小头条鼠标滑过 /* 头屏区滚动监听 */ var latestWidth = 0; var latestLength = $('#latest').find('li').length; $('#latest').find('li').each(function (index, item) { latestWidth += $(item).width() - 0; if (latestLength - 1 === index) { marquee('#latest ul', latestWidth, 70); } }); XHOME.scroll.monitorLoc({ selector: '#focus', height: $('#focus').height(), reference: 'winBottom', distants: 50, callback: function callback(res) { if (res.location === 'windowBottom' && res.status === 'show') { if (productIsFirstLoad) { addTopPart(); productIsFirstLoad = false; } } } }); /* 中间内容滚动监听 */ XHOME.scroll.monitorLoc({ selector: '#main', height: $('#main').height(), reference: 'winBottom', distants: 50, callback: function callback(res) { if (res.location === 'windowBottom' && res.status === 'show') { if (mainIsFirstLoad) { addCenterPart(); mainIsFirstLoad = false; } } } }); /* 底部内容滚动监听 */ XHOME.scroll.monitorLoc({ selector: '#bottom', height: $('#bottom').height(), reference: 'winBottom', callback: function callback(res) { if (res.location === 'windowBottom' && res.status === 'show') { if (bottomIsFirstLoad) { addBottomPart(); bottomIsFirstLoad = false; } } } }); /* 右侧导航 */ XHOME.scroll.monitorLoc({ selector: '#headline', height: 195, callback: function callback(res) { // // // console.log(res) var isShow = true; if (res.location === 'windowTop' && res.status === 'show') { // 页面down 从顶部出现 isShow = false; } if (res.location === 'windowTop' && res.status === 'hide') { // 页面up 从顶部消失 isShow = true; } if ($('#fixedNav')) { if (isShow) { $('#fixedNav').removeClass('hide'); } else { $('#fixedNav').addClass('hide'); } } } }); toTop(); closeFixedNav(); hideFixedNav(); $(window).resize(function () { hideFixedNav(); }); });