scroll to top .offset() using percentage %
问题 I just wrote this for scrolling pages which is working fine and does what it should.. $('#nav a').click(function(){ var sid = $(this).attr('id'); $('html,body').animate({ scrollTop: $('#'+ sid +'-content').offset().top - 200}, 1000); return false; }); ..but I want the offset to be calculated by % rather then px ie rather then top - 200 it could be top - 30% any ideas how to accomplish this? As always any help is appreciated and thanks in advance. Quick Edit: The current 3 answers (thank you)