Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add 100px offset to jQuery smooth scroll Plugin
/* Smooth Back to Top, Get This functionality from: http://wordpress.org/extend/plugins/cudazi-scroll-to-top/ */
jQuery.noConflict();
jQuery(function($) {
// When to show the scroll link
// higher number = scroll link appears further down the page
var upperLimit = 100;
// Our scroll link element
var scrollElem = $('a#scroll-to-top');
// Scroll to top speed
var scrollSpeed = 500;
// Show and hide the scroll to top link based on scroll position
scrollElem.hide();
$(window).scroll(function () {
var scrollTop = $(document).scrollTop();
if ( scrollTop > upperLimit ) {
$(scrollElem).stop().fadeTo(300, 1); // fade back in
}else{
$(scrollElem).stop().fadeTo(300, 0); // fade out
}
});
// Scroll to top animation on click
$(scrollElem).click(function(){
$('html, body').animate({scrollTop:100}, scrollSpeed); return false;
});
});
/* Anchorlink smooth scroll */
jQuery.noConflict();
jQuery(function($) {
$('a[href*=#]:not([href=#])').click(function()
{
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
|| location.hostname == this.hostname)
{
var target = $(this.hash),
headerHeight = $(".primary-header").height() + 5; // Get fixed header height
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length)
{
$('html,body').animate({
scrollTop: target.offset().top - 100
}, 500);
return false;
}
}
});
});
@l0ki000

This comment has been minimized.

Copy link

@l0ki000 l0ki000 commented Jul 6, 2016

headerHeight is not used

@mtedwards

This comment has been minimized.

Copy link

@mtedwards mtedwards commented Aug 12, 2016

I'm assuming line 52 should be:

   scrollTop: target.offset().top - headerHeight
@zems

This comment has been minimized.

Copy link

@zems zems commented Jan 9, 2017

Tab and accordion not open after add in this script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment