js acquisition scroll position, scroll to the specified position, smooth scrolling

1, to obtain information about the current position of the scroll bar

var Top = dom.scrollTop; // Get y-axis scroll position 
var left = dom.scrollLeft; // Get the scroll position of the x-axis

2, scroll to the specified location

= 150 dom.scrollTop; // scroll to position y-axis 150 (vertical direction) of 
dom.scrollLeft = 150; // Get the x-axis position 150 (horizontal direction)

3, smooth scrolling to the designated location

dom.scrollTo ({ 
  Top: 150 , 
  left: 150 , 
  behavior: 'Smooth' //   Smooth (smooth scrolling), Instant (instantaneous scrolling), default Auto 
});

 

Guess you like

Origin www.cnblogs.com/baikouLoser/p/11433232.html
Recommended