mirror of
https://github.com/Xevion/old.xevion.github.io.git
synced 2025-12-07 13:15:45 -06:00
working copy
This commit is contained in:
137
js/main.js
137
js/main.js
@@ -1,136 +1 @@
|
||||
$(function() {
|
||||
var contentSections = $('.section'),
|
||||
navigationItems = $('#dot-nav a'),
|
||||
overlayItems = $('#overlay a');
|
||||
updateNavigation();
|
||||
$(window).on('scroll', function() {
|
||||
updateNavigation();
|
||||
});
|
||||
//smooth scroll to the section
|
||||
navigationItems.on('click', function(event) {
|
||||
event.preventDefault();
|
||||
smoothScroll($(this.hash));
|
||||
});
|
||||
overlayItems.on('click', function(event) {
|
||||
event.preventDefault();
|
||||
smoothScroll($(this.hash));
|
||||
$('#toggle').click();
|
||||
});
|
||||
// smooth scroll to second section
|
||||
$('.scroll-down').on('click', function(event) {
|
||||
event.preventDefault();
|
||||
smoothScroll($(this.hash));
|
||||
});
|
||||
// close navigation on touch devices when selectinG an elemnt from the list
|
||||
$('.touch #dot-nav a').on('click', function() {
|
||||
$('.touch #dot-nav').removeClass('open');
|
||||
});
|
||||
|
||||
// ==================== VERTICAL NAV ON SCROLL ==================== //
|
||||
$(document).scroll(function() {
|
||||
var x = $(window).width();
|
||||
var y = $(this).scrollTop();
|
||||
var $nav = $('#dot-nav');
|
||||
if (x > 768 && y > 500) {
|
||||
$nav.fadeIn();
|
||||
} else {
|
||||
$nav.fadeOut();
|
||||
}
|
||||
});
|
||||
|
||||
function updateNavigation() {
|
||||
contentSections.each(function() {
|
||||
var $this = $(this);
|
||||
var activeSection = $('#dot-nav 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 smoothScroll(target) {
|
||||
$('body,html').animate({ 'scrollTop': target.offset().top + 50 }, 600);
|
||||
}
|
||||
|
||||
// ==================== MOBILE MENU ==================== //
|
||||
$('#toggle').click(function(e) {
|
||||
$(this).toggleClass('active');
|
||||
$('#overlay').toggleClass('open');
|
||||
$('body').toggleClass('noScroll');
|
||||
});
|
||||
$(window).on('resize', function(event) {
|
||||
var windowWidth = $(window).width();
|
||||
var isOpen = $('#overlay').hasClass('open');
|
||||
|
||||
if (windowWidth > 768) {
|
||||
$('#dot-nav').show();
|
||||
if (isOpen) {
|
||||
$('#toggle').removeClass('active');
|
||||
$('#overlay').removeClass('open');
|
||||
}
|
||||
} else if (windowWidth < 768) {
|
||||
$('#dot-nav').hide();
|
||||
}
|
||||
});
|
||||
|
||||
// ==================== CONTACT FORM ==================== //
|
||||
var $contactInput = $('.contact-input');
|
||||
$contactInput.focus(function() {
|
||||
$(this).parent().addClass('is-active is-completed');
|
||||
});
|
||||
$contactInput.focusout(function() {
|
||||
if ($(this).val() === "") {
|
||||
$(this).parent().removeClass('is-completed');
|
||||
}
|
||||
$(this).parent().removeClass('is-active');
|
||||
});
|
||||
|
||||
$(document).one('focus.textarea', '.autoExpand', function() {
|
||||
var savedValue = this.value;
|
||||
this.value = '';
|
||||
this.baseScrollHeight = this.scrollHeight;
|
||||
this.value = savedValue;
|
||||
})
|
||||
.on('input.textarea', '.autoExpand', function() {
|
||||
var minRows = this.getAttribute('data-min-rows') | 0,
|
||||
rows;
|
||||
this.rows = minRows;
|
||||
rows = Math.ceil((this.scrollHeight - this.baseScrollHeight) / 17);
|
||||
this.rows = minRows + rows;
|
||||
});
|
||||
|
||||
var isMobile = {
|
||||
Android: function() {
|
||||
return navigator.userAgent.match(/Android/i);
|
||||
},
|
||||
BlackBerry: function() {
|
||||
return navigator.userAgent.match(/BlackBerry/i);
|
||||
},
|
||||
iOS: function() {
|
||||
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
|
||||
},
|
||||
Opera: function() {
|
||||
return navigator.userAgent.match(/Opera Mini/i);
|
||||
},
|
||||
Windows: function() {
|
||||
return navigator.userAgent.match(/IEMobile/i);
|
||||
},
|
||||
any: function() {
|
||||
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
|
||||
}
|
||||
};
|
||||
|
||||
if (!isMobile.any()) {
|
||||
skrollr.init({
|
||||
render: function(data) {
|
||||
//Debugging - Log the current scroll position.
|
||||
// console.log(data.curTop);
|
||||
},
|
||||
smoothScrolling: false,
|
||||
forceHeight: false
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
"use strict";$(function(){function t(){n.each(function(){var t=$(this),o=$('#dot-nav a[href="#'+t.attr("id")+'"]').data("number")-1;t.offset().top-$(window).height()/2<$(window).scrollTop()&&t.offset().top+t.height()-$(window).height()/2>$(window).scrollTop()?e.eq(o).addClass("is-selected"):e.eq(o).removeClass("is-selected")})}function o(t){$("body,html").animate({scrollTop:t.offset().top+50},600)}var n=$(".section"),e=$("#dot-nav a"),i=$("#overlay a");t(),$(window).on("scroll",function(){t()}),e.on("click",function(t){t.preventDefault(),o($(this.hash))}),i.on("click",function(t){t.preventDefault(),o($(this.hash)),$("#toggle").click()}),$(".scroll-down").on("click",function(t){t.preventDefault(),o($(this.hash))}),$(".touch #dot-nav a").on("click",function(){$(".touch #dot-nav").removeClass("open")}),$(document).scroll(function(){var t=$(window).width(),o=$(this).scrollTop(),n=$("#dot-nav");t>768&&o>500?n.fadeIn():n.fadeOut()}),$("#toggle").click(function(t){$(this).toggleClass("active"),$("#overlay").toggleClass("open"),$("body").toggleClass("noScroll")}),$(window).on("resize",function(t){var o=$(window).width(),n=$("#overlay").hasClass("open");o>768?($("#dot-nav").show(),n&&($("#toggle").removeClass("active"),$("#overlay").removeClass("open"))):o<768&&$("#dot-nav").hide()});var a=$(".contact-input");a.focus(function(){$(this).parent().addClass("is-active is-completed")}),a.focusout(function(){""===$(this).val()&&$(this).parent().removeClass("is-completed"),$(this).parent().removeClass("is-active")}),$(document).one("focus.textarea",".autoExpand",function(){var t=this.value;this.value="",this.baseScrollHeight=this.scrollHeight,this.value=t}).on("input.textarea",".autoExpand",function(){var t=0|this.getAttribute("data-min-rows");this.rows=t;var o=Math.ceil((this.scrollHeight-this.baseScrollHeight)/17);this.rows=t+o});var s={Android:function(){return navigator.userAgent.match(/Android/i)},BlackBerry:function(){return navigator.userAgent.match(/BlackBerry/i)},iOS:function(){return navigator.userAgent.match(/iPhone|iPad|iPod/i)},Opera:function(){return navigator.userAgent.match(/Opera Mini/i)},Windows:function(){return navigator.userAgent.match(/IEMobile/i)},any:function(){return s.Android()||s.BlackBerry()||s.iOS()||s.Opera()||s.Windows()}};s.any()||skrollr.init({render:function(t){},smoothScrolling:!1,forceHeight:!1})});
|
||||
Reference in New Issue
Block a user