2021年2月2日星期二

How to get JS tab selector to not scroll

I'm using this JS for tabs. However, it continually makes the selected tab box scroll to the top of the page when clicked.

I can't figure out what part of it is doing that and am trying to get rid of it. Essentially I just want it to function as a normal tab clicker without causing the entire page to scroll.

Any help?

  function Tabs() {    var bindAll = function() {      var menuElements = document.querySelectorAll('[data-tab]');      for(var i = 0; i < menuElements.length ; i++) {        menuElements[i].addEventListener('click', change, false);      }    }      var clear = function() {      var menuElements = document.querySelectorAll('[data-tab]');      for(var i = 0; i < menuElements.length ; i++) {        menuElements[i].classList.remove('active');        var id = menuElements[i].getAttribute('data-tab');        document.getElementById(id).classList.remove('active');      }    }      var change = function(e) {      clear();      e.target.classList.add('active');      var id = e.currentTarget.getAttribute('data-tab');      document.getElementById(id).classList.add('active');    }      bindAll();  }    var connectTabs = new Tabs();   
https://stackoverflow.com/questions/66020655/how-to-get-js-tab-selector-to-not-scroll February 03, 2021 at 11:04AM

没有评论:

发表评论