Created
June 20, 2013 04:30
-
-
Save georgeOsdDev/5820311 to your computer and use it in GitHub Desktop.
To prepare flexible contents height change on Android device.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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