Line 3: | Line 3: | ||
* COPY TO https://2017.igem.org/Template:Erlangen_Nuremberg/Javascript | * COPY TO https://2017.igem.org/Template:Erlangen_Nuremberg/Javascript | ||
*/ | */ | ||
− | $(document).ready(function() { | + | /* |
+ | * VERTICAL NAV | ||
+ | */ | ||
+ | $(document).ready(function ($) { | ||
+ | var contentSections = $('.cd-section'), | ||
+ | navigationItems = $('#cd-vertical-nav').find('a'); | ||
− | + | updateSideNavPadding() | |
− | $( | + | updateNavigation(); |
+ | $(window).on('scroll', function () { | ||
+ | updateNavigation(); | ||
+ | updateSideNavPadding(); | ||
+ | }); | ||
− | + | //smooth scroll to the section | |
− | + | navigationItems.on('click', function (event) { | |
+ | event.preventDefault(); | ||
+ | smoothScroll($(this.hash)); | ||
+ | }); | ||
+ | //smooth scroll to second section | ||
+ | $('.cd-scroll-down').on('click', function (event) { | ||
+ | event.preventDefault(); | ||
+ | smoothScroll($(this.hash)); | ||
+ | }); | ||
− | + | //open-close navigation on touch devices | |
− | + | $('.touch .cd-nav-trigger').on('click', function () { | |
− | + | $('.touch #cd-vertical-nav').toggleClass('open'); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
+ | }); | ||
+ | //close navigation on touch devices when selectin an elemnt from the list | ||
+ | $('.touch #cd-vertical-nav a').on('click', function () { | ||
+ | $('.touch #cd-vertical-nav').removeClass('open'); | ||
}); | }); | ||
− | }); | + | function updateNavigation() { |
+ | contentSections.each(function () { | ||
+ | $this = $(this); | ||
+ | var activeSection = $('#cd-vertical-nav').find('a[href="#' + $this.attr('id') + '"]').data('number') - 1; | ||
+ | if (( $this.offset().top - $(window).height() / 2 < $(window).scrollTop() ) && ( $this.offset().top + $this.height() - $(window).height() / 2 > $(window).scrollTop() )) { | ||
+ | navigationItems.eq(activeSection).addClass('is-selected'); | ||
+ | } else { | ||
+ | navigationItems.eq(activeSection).removeClass('is-selected'); | ||
+ | } | ||
+ | }); | ||
+ | } | ||
− | + | function updateSideNavPadding() { | |
− | + | var nav = $('.no-touch #cd-vertical-nav'); | |
− | + | if (nav.length !== 1) return; | |
− | + | var banner = $('.banner'); | |
− | + | var bannerBottom = banner.offset().top + banner.height(); | |
− | $( | + | var differenceToTop = $(window).scrollTop() - bannerBottom; |
− | + | var differenceToBottom = $(document).height() - $(window).scrollTop() - $(window).height() - $('.bottom').height(); | |
− | + | if (differenceToTop < 0) { | |
− | + | nav.css('top', banner.offset().top + banner.height() + nav.height()); | |
− | }); | + | nav.css('bottom', 'auto'); |
+ | nav.css('position', 'absolute'); | ||
+ | } else if (differenceToBottom < 0) { | ||
+ | nav.css('top', 'auto'); | ||
+ | nav.css('bottom', Math.abs(differenceToBottom)); | ||
+ | nav.css('position', 'fixed'); | ||
+ | } else { | ||
+ | nav.css('bottom', 'auto'); | ||
+ | nav.css('top', '50%'); | ||
+ | nav.css('position', 'fixed'); | ||
+ | } | ||
} | } | ||
− | + | function smoothScroll(target) { | |
− | + | $('body,html').animate( | |
− | + | {'scrollTop': target.offset().top}, | |
− | + | 600 | |
− | + | ); | |
− | + | } | |
− | + | }); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | /* SMOOTH SCROLLING ON NAV CLICK */ | |
− | + | $(document).ready(function () { | |
− | + | $('a[href*="#"]').on('click', function (e) { | |
+ | if (!($(this.hash).length)) return true; | ||
− | + | e.preventDefault(); | |
− | + | ||
− | + | var target = this.hash; | |
− | + | var $target = $(target); | |
− | + | $('html, body').stop().animate({ | |
− | + | 'scrollTop': $target.offset().top | |
− | + | }, 900, 'swing', function () { | |
− | + | window.location.hash = target; | |
− | + | }); | |
− | + | }); | |
+ | }); | ||
− | |||
− | |||
− | |||
− | + | /* Slide Up/Slide Down Animation for Main Menu */ | |
+ | $(document).ready(function () { | ||
+ | $(".dropdown").hover( | ||
+ | function () { | ||
+ | $('.dropdown-menu', this).not('.in .dropdown-menu').stop(true, true).slideDown(300); | ||
+ | $(this).toggleClass('open'); | ||
+ | }, | ||
+ | function () { | ||
+ | $('.dropdown-menu', this).not('.in .dropdown-menu').stop(true, true).slideUp(300); | ||
+ | $(this).toggleClass('open'); | ||
+ | } | ||
+ | ); | ||
+ | }); | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | /* | |
− | + | * BEAM/PATHOMON LOGO SCALING | |
− | + | */ | |
− | + | $(document).ready(function () { | |
+ | $('#navbar').find('li.beam').hover(function () { | ||
+ | scaleDropdownLogo($(this)); | ||
+ | }, function () { | ||
+ | unscaleDropdownLogo($(this)); | ||
+ | }); | ||
− | + | $('#navbar').find('li.pathomon').hover(function () { | |
− | + | scaleDropdownLogo($(this)); | |
− | + | }, function () { | |
− | + | unscaleDropdownLogo($(this)); | |
− | + | }); | |
− | + | ||
− | + | function scaleDropdownLogo(element) { | |
− | + | element.find('.dropdown-logo').css('transform', 'scale(1.5, 1.5)'); | |
− | + | element.find('a').first().css('opacity', 1); | |
− | + | } | |
− | + | function unscaleDropdownLogo(element) { | |
− | + | element.find('.dropdown-logo').css('transform', 'scale(1, 1)'); | |
− | + | element.find('a').first().css('opacity', 0.8); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | } | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | } | + | |
}); | }); |
Revision as of 23:44, 30 October 2017
/**
* OUR JAVASCRIPT MODIFICATION GOES HERE * COPY TO https://2017.igem.org/Template:Erlangen_Nuremberg/Javascript */
/*
- VERTICAL NAV
*/
$(document).ready(function ($) { var contentSections = $('.cd-section'), navigationItems = $('#cd-vertical-nav').find('a');
updateSideNavPadding() updateNavigation(); $(window).on('scroll', function () { updateNavigation(); updateSideNavPadding(); });
//smooth scroll to the section navigationItems.on('click', function (event) { event.preventDefault(); smoothScroll($(this.hash)); }); //smooth scroll to second section $('.cd-scroll-down').on('click', function (event) { event.preventDefault(); smoothScroll($(this.hash)); });
//open-close navigation on touch devices $('.touch .cd-nav-trigger').on('click', function () { $('.touch #cd-vertical-nav').toggleClass('open');
}); //close navigation on touch devices when selectin an elemnt from the list $('.touch #cd-vertical-nav a').on('click', function () { $('.touch #cd-vertical-nav').removeClass('open'); });
function updateNavigation() { contentSections.each(function () { $this = $(this); var activeSection = $('#cd-vertical-nav').find('a[href="#' + $this.attr('id') + '"]').data('number') - 1; if (( $this.offset().top - $(window).height() / 2 < $(window).scrollTop() ) && ( $this.offset().top + $this.height() - $(window).height() / 2 > $(window).scrollTop() )) { navigationItems.eq(activeSection).addClass('is-selected'); } else { navigationItems.eq(activeSection).removeClass('is-selected'); } });
}
function updateSideNavPadding() { var nav = $('.no-touch #cd-vertical-nav'); if (nav.length !== 1) return; var banner = $('.banner'); var bannerBottom = banner.offset().top + banner.height(); var differenceToTop = $(window).scrollTop() - bannerBottom; var differenceToBottom = $(document).height() - $(window).scrollTop() - $(window).height() - $('.bottom').height(); if (differenceToTop < 0) { nav.css('top', banner.offset().top + banner.height() + nav.height()); nav.css('bottom', 'auto'); nav.css('position', 'absolute'); } else if (differenceToBottom < 0) { nav.css('top', 'auto'); nav.css('bottom', Math.abs(differenceToBottom)); nav.css('position', 'fixed'); } else { nav.css('bottom', 'auto'); nav.css('top', '50%'); nav.css('position', 'fixed'); } }
function smoothScroll(target) { $('body,html').animate( {'scrollTop': target.offset().top}, 600 ); } });
/* SMOOTH SCROLLING ON NAV CLICK */ $(document).ready(function () { $('a[href*="#"]').on('click', function (e) { if (!($(this.hash).length)) return true;
e.preventDefault();
var target = this.hash; var $target = $(target);
$('html, body').stop().animate({ 'scrollTop': $target.offset().top }, 900, 'swing', function () { window.location.hash = target; }); }); });
/* Slide Up/Slide Down Animation for Main Menu */
$(document).ready(function () {
$(".dropdown").hover(
function () {
$('.dropdown-menu', this).not('.in .dropdown-menu').stop(true, true).slideDown(300);
$(this).toggleClass('open');
},
function () {
$('.dropdown-menu', this).not('.in .dropdown-menu').stop(true, true).slideUp(300);
$(this).toggleClass('open');
}
);
});
/*
- BEAM/PATHOMON LOGO SCALING
- /
$(document).ready(function () { $('#navbar').find('li.beam').hover(function () { scaleDropdownLogo($(this)); }, function () { unscaleDropdownLogo($(this)); });
$('#navbar').find('li.pathomon').hover(function () { scaleDropdownLogo($(this)); }, function () { unscaleDropdownLogo($(this)); });
function scaleDropdownLogo(element) { element.find('.dropdown-logo').css('transform', 'scale(1.5, 1.5)'); element.find('a').first().css('opacity', 1); }
function unscaleDropdownLogo(element) { element.find('.dropdown-logo').css('transform', 'scale(1, 1)'); element.find('a').first().css('opacity', 0.8);
} });