Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm-debug.log
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "scrollfix",
"version": "0.0.2",
"description": "Small script to fix some of the issues with iOS5's overflow:scroll;",
"main": "scrollfix.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git://github.com/Techwraith/ScrollFix.git"
},
"keywords": [
"ios",
"browserify",
"scroll"
],
"author": "joelambert",
"license": "MIT",
"readmeFilename": "README.md",
"gitHead": "74730600030512323364fd5572f242583cc1bccb"
}
62 changes: 40 additions & 22 deletions scrollfix.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,43 @@
* http://www.opensource.org/licenses/mit-license.php
*/

var ScrollFix = function(elem) {
// Variables to track inputs
var startY, startTopScroll;

elem = elem || document.querySelector(elem);

// If there is no element, then do nothing
if(!elem)
return;

// Handle the start of interactions
elem.addEventListener('touchstart', function(event){
startY = event.touches[0].pageY;
startTopScroll = elem.scrollTop;

if(startTopScroll <= 0)
elem.scrollTop = 1;

if(startTopScroll + elem.offsetHeight >= elem.scrollHeight)
elem.scrollTop = elem.scrollHeight - elem.offsetHeight - 1;
}, false);
};
(function () {
var ScrollFix = function(elem) {
// Variables to track inputs
var startY, startTopScroll;

elem = elem || document.querySelector(elem);

// If there is no element, then do nothing
if(!elem) {
return;
}

// Handle the start of interactions
elem.addEventListener('touchstart', function(event){
startY = event.touches[0].pageY;
startTopScroll = elem.scrollTop;

if(startTopScroll <= 0) {
elem.scrollTop = 1;
}

if(startTopScroll + elem.offsetHeight >= elem.scrollHeight) {
elem.scrollTop = elem.scrollHeight - elem.offsetHeight - 1;
}

}, false);

};

// if we've got a window and we don't have a module
// create a global;
if ((typeof window != 'undefined') && (typeof module == 'undefined')) {
window.ScrollFix = ScrollFix;
}
// otherwise, export it.
else {
module.exports = ScrollFix;
}

})();