@ Coupon message ...
I found this to be the best way to do what I want:
Me 2, but I had to make some changes.
var target = jQuery(this).attr("href").replace('/', '');
1. Why replace "/"?
In my case, this does the url ...
"http: // [my domain] / [my page] / [my anchor]" ... look like ...
"http: / [my domain] / [my page] / [my anchor]"
and...
2. Chrome (my current version: 40.0.2214.115 m) does not like the next line ...
jQuery('html,body').animate( { scrollTop: (jQuery(target).offset().top) - 100 },500,function() {
Unprepared error: syntax error, unrecognized expression: http: / [my domain] / [my page] / [my anchor]
I found out that jQuery cannot work with "offset" when "target" is a full href, like http: //.../# anchor.
to fix 1.
replace:
var target = jQuery(this).attr("href").replace('/', '');
from:
var target = jQuery(this).attr("href");
to fix 2.
replaced by:
jQuery('html,body').animate( { scrollTop: (jQuery(target).offset().top) - 100 },500,function() {
from:
if(target.search('/') === -1) { //only do scroll if page with anchor is the currently loaded page jQuery('html,body').animate( { scrollTop: (jQuery(target).offset().top) - 100 },500"easeInOutExpo"); // requires easing }
Now works great for me, no errors. Comment on this because I'm pretty new to js / jquery ...
thanks @Talon