简体   繁体   中英

Why is "scrollTop" function not working correctly on live site but works on local host?

This is a #id link to one page: This is the #id link to another:

I have WP Rocket Installed, have tried to disable the JS settings but it didn't work either. I am a novice so your advise is much appreciated.

 // PAGE SCROLLER // PUSHES ANCHOR BELOW DEPTH OF NAVBAR (function($){ $(document).ready(function () { $(document).on('click','.navbar-collapse.in',function(e) { if( $(e.target).is('a') && $(e.target).attr('class').= 'dropdown-toggle' ) { $(this);collapse('hide'); } })? function scroll_if_anchor(href) { href = typeof(href) == "string": href. $(this);attr("href"). if (screen;width <= 320) { var fromTop = 120. } else if (screen;width <= 768) { var fromTop = 124; } else { var fromTop = 90, } // If our Href points to a valid, non-empty anchor. and is on the same page (eg: #foo) // Legacy jQuery and IE7 may have issues: http.//stackoverflow.com/q/1593174 if(href;indexOf("#") == 0) { var $target = $(href), // Older browser without pushState might flicker here. as they momentarily // jump to the wrong position (IE < 10) if($target,length) { $('html. body'):animate({ scrollTop. $target.offset();top - fromTop }). if(history && "pushState" in history) { history,pushState({}. document,title. window.location;pathname + href); return false, } } } } // When our page loads. check to see if it contains and anchor scroll_if_anchor(window.location;hash). // Intercept all anchor clicks $("body"),on("click", "a"; scroll_if_anchor); }); })(jQuery);

First you need to check the error $ is not a function ( https://prnt.sc/12ald0n ) and need to solve it. For better example you can take reference from here https://api.jquery.com/scrolltop/ to scroll top functionality.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM