Closed con322 closed 8 years ago
you could use the $.smoothScroll()
utility method in a click handler and pass an offset option based on the position
of the navbar. For example (you'll have to replace selectors, of course):
$('.some-class').on('click', function() {
var $navBar = $('#navbar');
$.smoothScroll({
scrollTarget: this.hash,
offset: $navBar.css('position') === 'fixed' ? -$navBar.height() : 0
});
});
when i try the above code obviously changing the selectors I get the following error any ideas?
Uncaught TypeError: jQuery.smoothScroll is not a function
The only thing I can think of is that maybe you're not referencing the plugin correctly before you call jQuery.smoothScroll
? Do you have a URL I can look at to investigate?
Here's link atm it works (not using your code using the below code) but you'll see first click on the links blow the page header scroll to the correct position but if you click the link again when not at the top it changes position.
http://middlers.plewscreative.co.uk/solutions-for-you/individuals/
smoothScroll.init({
offset: 190, // Integer. How far to offset the scrolling anchor location in pixels
});
ok, it looks like you're using someone else's plugin. Maybe this one?… https://github.com/cferdinandi/smooth-scroll
In any case, you'd probably want to change that offset to -190
.
Apologies I was testing different ones, have your locally and get the following error any ideas?
Uncaught TypeError: Cannot read property 'smoothScroll' of undefined
If you're calling $.smoothScroll
and getting that error, it means that $
is undefined. So, you either haven't loaded jQuery or it's in noConflict mode or some other situation where $
is not aliased to jQuery
. So, if you're sure jQuery is loaded, try jQuery.smoothScroll
instead.
@con322 : are you able to close this issue now, or do you need more help from me? I checked your site, and it looks like it's working. But please let me know if it's not.
Closing this due to lack of activity. If you need it re-opened or still have a question, please let me know.
Is there a quick fix/options that so that after the navbar is fixed the offset is changed?