Jquery: How to get Offset() negative value [SOLVED]
Go to solution
Solved by colonel_mortis,
Is there a reason that you can't just subtract from the value returned by .offset().top directly?
$("#post_1").click(function(){ $('html, body').animate({ scrollTop: $(".blpost_frame").offset().top - 5 // Scroll to 5px above the top of .blpost_frame }, 500) });
You have to specify the offset in pixels rather than any of the relative CSS units, but if you really need to use relative units then it is possible to convert them manually.
Offset is supposed to get the actual offset position, but it doesn't take into account margin on the html element (docs). Is it possible that you have a margin on the html element which is throwing off the offset calculation, so removing that would allow the code to work unmodified?
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now