0

fellas, I've looked everywhere with no luck. Can someone help me? I want to change data-offset-top attribute to two different values depending on the screen size. It works on reload but I cannot make it work on resize. What am I doing wrong? Here's the code.

strr();
window.addEventListener('resize', strr);

function strr() {
  if (window.outerWidth <= 767) {
    document.getElementById("navas").setAttribute("data-offset-top", 300);
  } else {
    document.getElementById("navas").setAttribute("data-offset-top", 650);
  }
}

btw #navas is a bootstrap nav element with affix.

Good luck!

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Vladas K
  • 181
  • 1
  • 1
  • 5

0 Answers0