Last active
November 9, 2017 14:45
-
-
Save yuriitaran/c6141fce082126e62f4b09dfee0c54a8 to your computer and use it in GitHub Desktop.
JQuery Starter functions for WP theme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Hide outline for all links | |
$('a').on('mousedown', function(){ | |
$(this).css('outline', 'none'); | |
}); | |
// Scroll to Main content | |
$( '.scroll-to-content' ).click(function() { | |
$('html, body').animate({ | |
scrollTop: ($('main').first().offset().top) | |
},800); | |
return false; | |
}); | |
// Add class 'active' to closest parental element in main-menu | |
$(".submenu li a").live({ | |
mouseenter: function () { | |
$(this).closest('.has-dropdown').addClass('current-menu-item'); | |
}, | |
mouseleave: function () { | |
$(this).closest('.has-dropdown').removeClass('current-menu-item'); | |
} | |
}); | |
// Scroll to Top button | |
if ($('.scroll-to-top').length) { | |
var scrollTrigger = 300, // px | |
backToTop = function () { | |
var scrollTop = $(window).scrollTop(); | |
if (scrollTop > scrollTrigger) { | |
$('.scroll-to-top').addClass('show'); | |
} else { | |
$('.scroll-to-top').removeClass('show'); | |
} | |
}; | |
backToTop(); | |
$(window).on('scroll', function () { | |
backToTop(); | |
}); | |
$('.scroll-to-top').on('click', function (e) { | |
e.preventDefault(); | |
$('html,body').animate({ | |
scrollTop: 0 | |
}, 800); | |
return false; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment