Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scroll to 10px above an element

Tags:

jquery

scroll

I'm using the following code to scroll to the top of an element but I'd like to scroll 10px above the top of the element, not sure how I could do this, any suggestions? Thanks!

  $('html, body').stop(true,true).animate({
             scrollTop: $(".career-overlay").offset().top
    }, 2000)
like image 451
user1937021 Avatar asked Jun 03 '13 14:06

user1937021


People also ask

How do I scroll to the top of a div?

We can use the scroll method of an element to scroll a scrollable div back to the top. Then we can add some content to the div and make the div scroll to the top when we click the button by writing: const div = document. querySelector('div') for (let i = 0; i < 100; i++) { const p = document.

How do you scroll within an element?

// get the "Div" inside which you wish to scroll (i.e. the container element) const El = document. getElementById('xyz'); // Lets say you wish to scroll by 100px, El. scrollTo({top: 100, behavior: 'smooth'}); // If you wish to scroll until the end of the container El. scrollTo({top: El.

How do you scroll to the top in HTML?

window. scrollTo(0, 0); …is a sure bet to scroll the window (or any other element) back to the top.

How do I scroll down to a specific element in JavaScript?

Scrolling to an element can be achieved in Javascript using the scrollIntoView() method. Smooth animation and customizing the alignment can be set through the scrollIntoViewOptions parameter.


1 Answers

Like this:

$('html, body').stop(true,true).animate({
    scrollTop: $(".career-overlay").offset().top - 10
}, 2000)
like image 164
johnkavanagh Avatar answered Sep 25 '22 13:09

johnkavanagh