jaridmargolin / bouncefix.js

🚫 Stop full body elastic scroll bounce when scrolling inside nested containers (IOS)
http://jaridmargolin.github.io/bouncefix.js/
84 stars 15 forks source link

FYI scrolling manipulation on click #4

Open jensstalder opened 10 years ago

jensstalder commented 10 years ago

When I have anchors in a scrollable div, tapping on it causes the div do scroll down 1px if its on top. This causes iOS to register a change after tap and initializes a pause until re-tap. This is a behavior of iOS to allow drop downs and the like to function.

utils.scrollToEnd = function (el) {
    var curPos = el.scrollTop, height = el.offsetHeight, scroll = el.scrollHeight;
    // If at top, bump down 1px
    if (curPos <= 0) {
      el.scrollTop = 1; // <<<<< HERE
    }
    // If at bottom, bump up 1px
    if (curPos + height >= scroll) {
      el.scrollTop = scroll - height - 1;
    }
  };