jQuery scroll action

I am attempting to implement two types of jQuery scroll actions. The first causes the browser window to scroll to an anchor tag link. The second causes the browser to scroll to the top of the window. They seem to be interfering with each other, however, depending on which I click first. Can anyone please help resolve this? Thank you.

<script> $(document).ready(function(){ $('a[href^="#"]').on('click',function (e) { e.preventDefault(); var target = this.hash; var $target = $(target); $('html, body').stop().animate({ 'scrollTop': $target.offset().top - 85 }, 750, function () { window.location.hash = href; }); }); $('.top').on('click', function(){ $('html, body').animate({scrollTop: '0px'}, 1000); }); }); </script>

Ah. I believe I fixed it. <script> $(document).ready(function(){ $('.top').on('click', function(){ $('html, body').animate({scrollTop: '0px'}, 1000); }); }); $(document).ready(function(){ $('a[href^="#"]').on('click',function (e) { e.preventDefault(); var target = this.hash; var $target = $(target); $('html, body').stop().animate({ 'scrollTop': $target.offset().top - 85 }, 1000); }); }); </script>

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.