Skip to content

Instantly share code, notes, and snippets.

@anandkumar
Created April 26, 2014 12:06
Show Gist options
  • Save anandkumar/11318494 to your computer and use it in GitHub Desktop.
Save anandkumar/11318494 to your computer and use it in GitHub Desktop.
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;
}
}
});
});
@mtedwards
Copy link

I'm assuming line 52 should be:

   scrollTop: target.offset().top - headerHeight

@kamalktwl
Copy link

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