J
J
jertik22018-02-21 02:55:40
JavaScript
jertik2, 2018-02-21 02:55:40

How to stop scrolling in exact place?

The wheel event does not fire every 100px or more. And I need pixel-perfect to stop at the right place using JS.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2018-02-21
@Stalker_RED

To do this, you need to reduce the sensitivity of the wheel in the operating system to one pixel per tick.
(Hint: none of your users will be doing this kind of bullshit.)
A more realistic plan: move the scroll yourself when the user has scrolled approximately where you need.

B
BooksScriptor, 2018-02-21
@BooksScriptor

#elem {
 position: absolute; // ваши параметры
 top: 30px;
 left: 30px;
 
 }
.fixed_elem {
 position: fixed !important; 
 top: 10px !important;  // ваши параметры
 left: 10px !important;
 }

var elem=document.getElementById('elem');
window.onscroll=fixed_scroll;
function fixed_scroll() {
 if(window.pageYOffset > 100) {  // ваша высота
   elem.classList.add('fixed_elem');} else {
    elem.classList.remove('fixed_elem')}
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question