Anchor does not work

I have a problem with a link inside the page. This is part of the jQuery code that I use on my page

$.fn.stopAtTop= function () { var $this = this, $window = $(window), thisPos = $this.offset().top, //thisPreservedTop = $this.css("top"), setPosition, under, over; under = function(){ if ($window.scrollTop() < thisPos) { $this.css({ position: 'absolute', top: "" }); setPosition = over; } }; over = function(){ if (!($window.scrollTop() < thisPos)){ $this.css({ position: 'fixed', top: 0 }); setPosition = under; } }; setPosition = over; $window.resize(function() { bumperPos = pos.offset().top; thisHeight = $this.outerHeight(); setPosition(); }); $window.scroll(function(){setPosition();}); setPosition(); }; 

And this is an example of demo

When I scroll down, everything works fine, but when I want to get to the top of the page, this is not possible. I know the problem is that the script corrects the div , but I don't know how to fix it. Any ideas?

+5
source share
1 answer

Add a click handler that scrolls to the top of the page:

 $("[href='#one']").click(function() { scrollTo(0, 0); }); 

jsfiddle.net/jx8nmhfq/1

+2
source

Source: https://habr.com/ru/post/1236657/


All Articles