Skip to content

Instantly share code, notes, and snippets.

@yuriitaran
Last active November 9, 2017 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuriitaran/c6141fce082126e62f4b09dfee0c54a8 to your computer and use it in GitHub Desktop.
Save yuriitaran/c6141fce082126e62f4b09dfee0c54a8 to your computer and use it in GitHub Desktop.
JQuery Starter functions for WP theme
// 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