0

Right now I have this pretty easy code

<h1 id="testpos">HEADLINE</h1>
<form method="post" action="#testpos">

However, since my horizontal menu bar is always fixed on top, I need it to scroll to the #testpos div + height of the menu bar (I know the height)

Any way to do this?

Desii
  • 35
  • 1
  • 8
  • Thats quite the vague question without any real code attempts to go on. Are you using jquery? Are you using any jquery plugins? Looking for strictly vanilla js methods? – IncredibleHat Mar 30 '18 at 17:51
  • Sorry, im still quite a newbie and I can't use jquery yet so hopefully some way in js or php – Desii Mar 30 '18 at 17:55
  • You can use Jquery, it's very easy... – ArtisticPhoenix Mar 30 '18 at 17:57
  • Jquery is actually a good thing for newbie's... it helps you get rolling and doing all manner of js goodness without dealing with a lot of the nittygritty. But yes, this can be done in vanilla javascript (since jquery is just a layer). It cannot really be done in PHP, since php just builds the page to be output. – IncredibleHat Mar 30 '18 at 17:59
  • 1
    Er actually... were you wanting smooth scrolling, or just anchor snapping? You wouldn't need any javascript to do this if you just want it to snap up to that `h1`. Just offset with css (see above duplicate link). – IncredibleHat Mar 30 '18 at 18:02
  • @EdKorket thanks your solution worked! – Desii Mar 30 '18 at 18:04

0 Answers0