/** * Template Name: Moderna - v2.0.0 * Template URL: https://bootstrapmade.com/free-bootstrap-template-corporate-moderna/ * Author: BootstrapMade.com * License: https://bootstrapmade.com/license/ */ var $window=$(window); function headerTopFn(){ return $window.width()*0.3 } !(function($) { "use strict"; var $window=$(window); var $body=$('body'); let phoneBool=$window.width()<992; $window.resize(function() { phoneBool=$window.width()<992; $('.sideBar').width($('.sideBar').parent().width()); //console.log('sideBar') }) $window.scroll(function() { if ($(this).scrollTop() > headerTopFn()) { $body.addClass('body-scrolled'); } else { $body.removeClass('body-scrolled'); } if ($(this).scrollTop() > headerTopFn()+90) { $body.addClass('body-sideBar-scrolled'); } else { $body.removeClass('body-sideBar-scrolled'); } }); $('#header').addClass('h610'); $window.trigger('resize').trigger('scroll'); $('.sideBar').on('click','li',function(){ var $this=$(this); var index=$this.index() var title=$this.text() $('.text-content-item').hide(); $('.text-content-item-'+(index+1)).show(); $('.text-content-item[data-prop="'+title+'"]').show(); sessionStorage[location.href]=JSON.stringify({index,title}) $('.sideBar li.active').removeClass('active'); $this.addClass('active'); $('.smallTitle').text(title); var header=headerTopFn()+90 if(document.documentElement.scrollTop>header){ window.scrollTo(0,headerTopFn()+70); } $body.toggleClass('static',$('.text-content').height()<$('.sideBar').height()); AOSFn(); }) $('.text-content-item').hide(); let text23113=sessionStorage[location.href]; if(location.href.includes('/article')||location.href.includes('/video')){ $('.text-content-item:eq(0)').show(); }else if(text23113){ text23113=JSON.parse(text23113) //$('.text-content-item-'+(text23113.index+1)).show(); //$('.text-content-item[data-prop="'+text23113.title+'"]').show(); $('.sideBar li:eq('+text23113.index+')').click() }else if(locationfn('text')!=''){ var text=decodeURI(locationfn('text')); $('.sideBar li').each(function(){ var $this=$(this); if($this.text()==text){ $this.click(); } }) }else { $('.text-content-item:eq(0)').show(); } $body.toggleClass('static',$('.text-content').height()<$('.sideBar').height()) var pathname=location.pathname.split('/').slice(-1)[0]; $('.nav-menu>ul>li').removeClass('active') if(pathname==''){ $('.nav-menu>ul>li:eq(0)').addClass('active') var text=$('.nav-menu>ul>li.active>a').text(); }else if(location.href.includes('/article')||location.href.includes('/video')){ if(location.href.includes('/article')){ text='文章动态' }else{ text='科普视频' } $('.nav-menu>ul>li:eq(4)').addClass('active') }else{ $('.nav-menu>ul>li>a').each(function(){ var $a=$(this); var href=$a.attr('href'); if(href.includes(pathname)){ $a.parents('li').addClass('active') } }) var text=$('.nav-menu>ul>li.active>a').text(); } $('title:eq(1)').remove() $body.on('click','.back',function(){ localStorage['headerTopBool']=1; history.back() }) if(localStorage['headerTopBool']==1){ localStorage['headerTopBool']=0; window.scrollTo(0,headerTopFn()); } $body.on('click','.pointer[data-href]',function(){ var $this=$(this); var href=$this.attr('data-href'); var target=$this.attr('target'); if(target=='_blank'){ window.open(href); }else{ location.href=href } localStorage['headerTopBool']=1; }) // Toggle .header-scrolled class to #header when page is scrolled /*$(window).scroll(function() { if ($(this).scrollTop() > 700) { $('#header').addClass('header-scrolled'); } else { $('#header').removeClass('header-scrolled'); } }); if ($(window).scrollTop() > 700) { $('#header').addClass('header-scrolled'); }*/ // Smooth scroll for the navigation menu and links with .scrollto classes $(document).on('click', '.nav-menu a, .mobile-nav a, .scrollto', function(e) { if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) { e.preventDefault(); var target = $(this.hash); if (target.length) { var scrollto = target.offset().top; var scrolled = 20; if ($('#header').length) { scrollto -= $('#header').outerHeight() if (!$('#header').hasClass('header-scrolled')) { scrollto += scrolled; } } if ($(this).attr("href") == '#header') { scrollto = 0; } $('html, body').animate({ scrollTop: scrollto }, 1500, 'easeInOutExpo'); if ($(this).parents('.nav-menu, .mobile-nav').length) { $('.nav-menu .active, .mobile-nav .active').removeClass('active'); $(this).closest('li').addClass('active'); } if ($('body').hasClass('mobile-nav-active')) { $('body').removeClass('mobile-nav-active'); $('.mobile-nav-toggle i').toggleClass('bx-menu bx-x'); $('.mobile-nav-overly').fadeOut(); } return false; } } }); // Mobile Navigation if ($('.nav-menu').length) { var $mobile_nav = $('.nav-menu').clone().prop({ class: 'mobile-nav d-lg-none' }); $('body').append($mobile_nav); $('body').prepend(''); $('body').append('
'); $(document).on('click', '.mobile-nav-toggle', function(e) { $('body').toggleClass('mobile-nav-active'); $('.mobile-nav-toggle i').toggleClass('bx-menu bx-x'); $('.mobile-nav-overly').toggle(); }); $(document).on('click', '.mobile-nav .drop-down > a', function(e) { e.preventDefault(); $(this).next().slideToggle(300); $(this).parent().toggleClass('active'); }); $(document).click(function(e) { var container = $(".mobile-nav, .mobile-nav-toggle"); if (!container.is(e.target) && container.has(e.target).length === 0) { if ($('body').hasClass('mobile-nav-active')) { $('body').removeClass('mobile-nav-active'); $('.mobile-nav-toggle i').toggleClass('bx-menu bx-x'); $('.mobile-nav-overly').fadeOut(); } } }); } else if ($(".mobile-nav, .mobile-nav-toggle").length) { $(".mobile-nav, .mobile-nav-toggle").hide(); } // Real view height for mobile devices if (window.matchMedia("(max-width: 767px)").matches) { $('#hero').css({ height: $(window).height() }); } // Intro carousel var heroCarousel = $("#heroCarousel"); heroCarousel.on('slid.bs.carousel', function(e) { $(this).find('h2').addClass('animated fadeInDown'); $(this).find('p').addClass('animated fadeInUp'); $(this).find('.btn-get-started').addClass('animated fadeInUp'); }); // Back to top button $(window).scroll(function() { if ($(this).scrollTop() > 100) { $('.back-to-top').fadeIn('slow'); } else { $('.back-to-top').fadeOut('slow'); } }); $('.back-to-top').click(function() { $('html, body').animate({ scrollTop: 0 }, 1500, 'easeInOutExpo'); return false; }); // Initiate the venobox plugin $(window).on('load', function() { $('.venobox').venobox(); }); // jQuery counterUp $('[data-toggle="counter-up"]').counterUp({ delay: 10, time: 1000 }); // Skills section $('.skills-content').waypoint(function() { $('.progress .progress-bar').each(function() { $(this).css("width", $(this).attr("aria-valuenow") + '%'); }); }, { offset: '80%' }); // Testimonials carousel (uses the Owl Carousel library) $(".testimonials-carousel").owlCarousel({ autoplay: true, dots: true, loop: true, items: 1 }); // Porfolio isotope and filter $(window).on('load', function() { var portfolioIsotope = $('.portfolio-container').isotope({ layoutMode: 'fitRows' }); $('#portfolio-flters li').on('click', function() { $("#portfolio-flters li").removeClass('filter-active'); $(this).addClass('filter-active'); portfolioIsotope.isotope({ filter: $(this).data('filter') }); }); }); // Initi AOS AOSFn(); setTimeout(function(){ AOSFn(); },3000) var imgLength=$('#main img').length; var i_img=0; $('#main img').on('load',function(){ i_img++; imgLengthFn(); }).on('error',function(){ //$(this).hide(); i_img++; imgLengthFn(); }) function imgLengthFn(){ //console.log(i_img,imgLength) if(i_img==imgLength){ AOSFn(); $window.trigger('resize').trigger('scroll') $body.toggleClass('static',$('.text-content').height()<$('.sideBar').height()); } } })(jQuery); function AOSFn(){ AOS.init({ duration: 1000, easing: "ease-in-out-back" }); } function imgErFn(that){ var $this=$(that); //console.log($this) if($this.hasClass('defaultImgClass')){ return ; } var src=$this.attr('src'); if(src.indexOf('http:',1) > 0){ var index=src.indexOf('http:',1); src=src.slice(index); }else if(src.indexOf('https:',1)>0){ var index=src.indexOf('https:',1); src=src.slice(index); }else{ var src='./modern/assets/img/default.jpg' $this.addClass('defaultImgClass') } $this.attr('src',src) var index231110=$this.attr('data-index231110'); if(index231110=='index'){ $this.parent().css('background-image','url('+src+')') } } /*获取地址上对应的参数*/ function locationfn(x){// var str=location.href; var num=str.indexOf("?"); str=str.slice(num); num=str.indexOf('?'+x); if(num==-1){ num=str.indexOf('&'+x); if(num==-1){ return ""; } } num++; str=str.slice(num+x.length+1); var lastNum=str.indexOf("&"); if(lastNum!=-1){ str=str.slice(0,lastNum); } return str; }