Hi,
I have got a function, which is scrolling me to a section of web.
I was trying to add px
value. to offset({top:200,left:0})
, but then, is happend something strange - the header of website is overruning to the section.
How can I properly add px
value to this code below?
Thank you in advance.
var $j = jQuery.noConflict();
var scrollToSection = function(event) {
var href = $j(this).attr('href');
if(typeof href === 'string' && href.trim().substr(0, 1) === '#'){
var px = $j(href).offset().top;
event.preventDefault();
console.log('Scrolling to ' + href + ' at position ' + px + 'px');
$j('html, body').animate({
scrollTop: px
}, 750);
return false;
}
};
$j(document).on('click', 'a', scrollToSection);