Skip to content

Instantly share code, notes, and snippets.

@georgeOsdDev
Created June 20, 2013 04:30
Show Gist options
  • Select an option

  • Save georgeOsdDev/5820311 to your computer and use it in GitHub Desktop.

Select an option

Save georgeOsdDev/5820311 to your computer and use it in GitHub Desktop.
To prepare flexible contents height change on Android device.
// append this element into last of body contents
// <div id="buffer" style="heigh:3000px;visibility:hidden;"></div>
App = {};
App.stopOverflow = function(){
const scrollStopper = 960,
scrollBack = 1060,
duration = 400;
var lastScrollY = 0,
startTouch = {},
endTouch = {},
isAnimating = false;
function saveCurrentPos(e){
lastScrollY = window.scrollY;
startTouch = endTouch = e.originalEvent.targetTouches[0];
}
function saveMovedPos(e){
endTouch = e.originalEvent.targetTouches[0];
}
$(document).bind("scroll", function(e) {
if (startTouch.pageY > endTouch.pageY && lastScrollY < window.scrollY && $("#buffer").offset().top - window.scrollY < scrollStopper){
e.preventDefault();
$(document).bind("touchmove", function(evt) {
evt.preventDefault();
});
if(!isAnimating){
isAnimating = true;
$('html, body').animate({ scrollTop: $("#buffer").offset().top - scrollBack },duration,'linear',function(){
$(document).unbind("touchmove").on('touchmove',saveMovedPos);
isAnimating = false;
});
}
return false;
}
}).on('touchstart',saveCurrentPos).on('touchmove',saveMovedPos);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment