Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

143
Views
Offset/ Change Scroll Function JS Anchor

Hey I have the following problem:

I have to work with code from a different agency and the scroll to function is not working properly because of the fixed header.

When the header is collapsed(minified), it scroll to a dynamic height and displays correctly, however if the header is not collapsed, the scroll functions stops earlier because it thinks the header is still big when it stops, however the header gets minified when scrolling down.

I tried static values instead of $('header').height(), but this messes up compability with other devices.

Any advice for a better solution? Thanks in advance.

;( function( Tao ) {
Tao.defer( function( $ ) {
    $( document ).on( 'click', 'a[href^="#"].scrollUp', function( e ) {
        e.preventDefault();
        e.stopPropagation();
        e.stopImmediatePropagation();

        var target = this.hash;
        $( 'html, body' ).stop().animate( {
            scrollTop: 0
        }, 900, 'swing', function() {
            window.location.hash = target;
        } );
    } );

    $( document ).on( 'click', 'a[href^="#"]', function( e ) {
        e.preventDefault();
        e.stopPropagation();
        e.stopImmediatePropagation();
        var target = this.hash;
        var $item = $( this.hash );

        if ( ! $item ) {
            return;
        }


        $( 'html, body' ).stop().animate( {
            scrollTop: $item.offset().top - $('header').height()
            //scrollTop: $item.offset().top - 129
        }, 750, 'swing', function() {
            history.pushState( {}, '', target );
        } );



    } );


    $( document ).ready( function() {
        if ( document.location.hash ) {
            var $item = $( document.location.hash );

            $( 'html, body' ).stop().animate( {
                scrollTop: $item.offset().top - $('header').height()
            } );
        }
    } );

} );
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!