解决苹果微信浏览器下拉回弹效果

.content是需要滑动的部分

var overscroll = function(el) {
      el.addEventListener('touchstart', function() {
          var top = el.scrollTop
          ,totalScroll = el.scrollHeight
          ,currentScroll = top + el.offsetHeight;
          if(top === 0) {
              el.scrollTop = 1;
          }else if(currentScroll === totalScroll) {
              el.scrollTop = top - 1;
          }
      });

      el.addEventListener('touchmove', function(evt) {
          if(el.offsetHeight < el.scrollHeight)
              evt._isScroller = true;
          });
      }
      overscroll(document.querySelector('.content'));
      document.body.addEventListener('touchmove', function(evt) {
          if(!evt._isScroller) {
              evt.preventDefault();
          }
      });

你可能感兴趣的:(js,微信)