-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
25 lines (21 loc) · 968 Bytes
/
Copy pathcontent.js
File metadata and controls
25 lines (21 loc) · 968 Bytes
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
(function() {
// Проверка на инициализацию переменной для хранения последней позиции прокрутки
if (typeof window.LastScroll === 'undefined') {
window.LastScroll = 0;
}
const currentScroll = window.scrollY; // Текущая позиция по вертикали
// Если НЕ в самом верху страницы
if (currentScroll > 0) {
// Запись текущей позиции страницы
window.LastScroll = currentScroll;
// Скролл в самый верх
window.scrollTo({ top: 0, behavior: 'auto' });
}
// Если УЖЕ в самом верху страницы
else {
// Возврат к сохранённой позиции страницы
if (window.LastScroll > 0) {
window.scrollTo({ top: window.LastScroll, behavior: 'auto' });
}
}
})();