I am getting Uncaught TypeError: Cannot read property 'offset' of undefined
Before that i was getting same exception for 'top' from same block. I fixed it in one way now, I am getting the error with 'offset'.
Here is my code.
var ssSmoothScroll = function() {
$('.smoothscroll').on('click', function (e) {
if (this.hash !== "" && this.pathname == window.location.pathname) {
var target = this.hash;
// $target = $(target);
e.preventDefault();
e.stopPropagation();
var topOffset = 0; //#top should default to 0 so no need to calculate the difference between top and top :)
if (target != "#top") { //If the target is not "#top", then calculate topOffset
var topOffset = $(target).offset().top;
}
}
else{
var target = this.hash,
$target = $(target);
e.preventDefault();
e.stopPropagation();
}
$('html, body').stop().animate({
'scrollTop': $target.offset().top
}, cfg.scrollDuration, 'swing', function () {
window.location.hash = target;
});
});
};
Any help is appreciated :)
this
refers to event argument. according to this page @Dez