scrollDocument function hash var self this if hash hash length if hash

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
scrollDocument: function (hash) {
var self = this;
if (hash && hash.length > 0) {
if (hash.substr(0, 1) == '/')
return;
try {
var el = $('#' + hash + ', a[name="' + hash + '"]');
if (el.length > 0) {
var $window = $(window),
scroll_time = (new Date).getTime(),
scroll_interval;
var disable_scroll = function (e) {
if (e) {
if (e.type == "scroll" && e.originalEvent)
return;
}
console.error("disable_scroll");
clearInterval(scroll_interval);
self.scroll_interval = null;
$(window).off('.auto_scroller');
};
var scroller = function () {
$window.scrollTop(el.offset().top);
if ((new Date).getTime() - scroll_time > 30000)
disable_scroll();
};
scroll_interval = setInterval(scroller, 300);
scroller();
var events = "touchmove.auto_scroller keydown.auto_scroller click.auto_scroller" +
"MozMousePixelScroll.auto_scroller mousewheel.auto_scroller wheel.auto_scroller scroll.auto_scroller";
$(window).on(events, disable_scroll);
return;
}
} catch (e) { console.error(e); }
}
window.scrollTo(0, 0);
},