Skip to content

Instantly share code, notes, and snippets.

@trangsihung
Last active December 7, 2017 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save trangsihung/5c87afd048bb9b73746b to your computer and use it in GitHub Desktop.
Save trangsihung/5c87afd048bb9b73746b to your computer and use it in GitHub Desktop.
jQuery Scripts
//Check to see if the window is top if not then display button
$(window).scroll(function(){
if ($(this).scrollTop() > 100) {
$('.scrollToTop').fadeIn();
} else {
$('.scrollToTop').fadeOut();
}
});
//Click event to scroll to top
$('.scrollToTop').click(function(){
$('html, body').animate({scrollTop : 0},800);
return false;
});
var menu = $('.site-header .top-header');
$(window).scroll(function() {
if ($(window).scrollTop() > 100 && !menu.hasClass('fixed')) {
menu.addClass('fixed');
// $('.site-header').css(minHeight, 0);
} else if ($(window).scrollTop() == 0) {
menu.removeClass('fixed');
// $('.site-header').css(minHeight, '');
}
});
$('.top-nav a').on('click', function(e) {
e.preventDefault();
target = $(this).attr('href');
$('html, body').animate({
scrollTop : $(target).offset().top
},800);
});
var container = $('.main-menu-outer'),
menu = container.find('.vtown-main-menu'),
menuToggle = container.find('.menu-stack a');
menuToggle.on('click', function(e) {
e.preventDefault();
menu.stop(true,true).slideToggle(400);
});
_resize();
$(window).resize(function(event) {
_resize();
});
function _resize() {
if ( $(window).width() > 1200 ) {
$('.main-menu-outer .vtown-main-menu').css('display', 'block');
} else {
$('.main-menu-outer .vtown-main-menu').css('display', 'none');
}
}
var sections = $(' .section');
var navigation_links = $('#about-nav li a');
navigation_links.on('click', function(e) {
e.preventDefault();
navigation_links.removeClass('active');
$(this).addClass('active');
target = $(this).attr('href');
topSpacing = $('.site-header').height() + 40;
$('html, body').animate({
scrollTop : $(target).offset().top - topSpacing
},800);
});
sections.waypoint({
handler: function (direction) {
var active_section;
active_section = $('#' + this.element.id);
// if (direction === "down") active_section = active_section.next();
if (direction === "up") active_section = active_section.prev();
var active_link = $('#about-nav li a[href="#' + active_section.attr("id") + '"]');
navigation_links.removeClass("active");
active_link.addClass("active");
},
offset: 120
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment