Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. $('.click-menu-element').click(function(){
  2. $('html, body').animate({scrollTop:$('#elementId').position().top}, 2000);
  3. });
  4.  
  5. function smoothScroll(Element) {
  6.  
  7. Element = document.getElementById(Element);
  8. var selectedPosX = 0;
  9. var selectedPosY = 0;
  10. while (Element != null) {
  11. selectedPosX += Element.offsetLeft;
  12. selectedPosY += Element.offsetTop;
  13. Element = Element.offsetParent;
  14. }
  15. window.scrollTo(selectedPosX, selectedPosY);
  16. }
  17.  
  18. html {
  19. scroll-behavior: smooth;
  20. }
  21.  
  22. <button class="btn" onclick="smoothScroll('myId')">туда</button>
  23. <p id="myId">тут</p>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement