-2

I was looking for a script that automatically scrolls to the closest anchor point e.g. when between pages.

Just like on this website http://cihadturhan.com/

Captain Obvlious
  • 19,754
  • 5
  • 44
  • 74
Cem
  • 3
  • 2
  • Did you find something? – reyaner Sep 20 '16 at 07:08
  • No can't find something close to that on the website. Seems to be selfmade – Cem Sep 20 '16 at 07:09
  • I think you are looking for this one : http://stackoverflow.com/questions/25839487/auto-scroll-to-next-anchor-at-mouse-wheel – Ömer Fadıl Usta Sep 20 '16 at 07:19
  • Close to that. I'm looking for one where you have full control of the scrolling but it scrolls automatically to the center of the next page, when you are between those two. Just like on the website I linked http://cihadturhan.com/ – Cem Sep 20 '16 at 07:39

1 Answers1

-1

I hacked together a fiddle which behaves like the page you mentioned.

I used the following snippet to check when a scroll event ended:

$.fn.scrollStopped = function(callback) {
  var that = this
  var $this = $(that);
  $this.scroll(function(ev) {
    clearTimeout($this.data('scrollTimeout'));
    $this.data('scrollTimeout', setTimeout(callback.bind(that), 250, ev));
  });
};

Then I compared the offsets from the sections with the window offset (in order to find the closest).

Here is the demo:

https://jsfiddle.net/cz8gz8cd/

(The code could need some improvement)

n1ru4l
  • 488
  • 1
  • 10
  • 29