scroll - Jquery scrollTop() with offset? -


i using jquery scrolltop(), , have issues

this html

<a class="jumper" href="#first">jump</a>  <div class="first"></div> <div id="second"></div> <div id="third"></div> <div id="fourth"></div> <div id="fifth"></div> 

and jquery

  $(document).ready(function () {          $('.jumper').click(function () {              $('html, body').animate({                 scrolltop: $("#fourth").offset().top             }, 2000);          });       }); 

it working ok, need, not scroll element #third top of page, scroll little under few px smaller 100px, because want leave in previous element seen to, possible?

here working fiddle

http://jsfiddle.net/x9fug/4/

i want leave yellow element seen abaout 100px?

note there may better solutions... first thing spings mind subtracting 100.

$("#fourth").offset().top - 100 

offset().top returns number without 'px' part, doing offset().top - 100 should work fine. (https://api.jquery.com/offset/)


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -