Created
April 26, 2014 12:06
-
-
Save anandkumar/11318494 to your computer and use it in GitHub Desktop.
Add 100px offset to jQuery smooth scroll Plugin
This file contains hidden or 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
/* 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; | |
} | |
} | |
}); | |
}); |
I'm assuming line 52 should be:
scrollTop: target.offset().top - headerHeight
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
headerHeight
is not used