Mercurial > hg > dml-open-vis
annotate src/DML/VendorAssetsBundle/Resources/assets/scrollfix/0.1/scrollfix.js @ 1:f38015048f48 tip
Added GPL
author | Daniel Wolff |
---|---|
date | Sat, 13 Feb 2016 20:43:38 +0100 |
parents | 493bcb69166c |
children |
rev | line source |
---|---|
Daniel@0 | 1 /** |
Daniel@0 | 2 * ScrollFix v0.1 |
Daniel@0 | 3 * http://www.joelambert.co.uk |
Daniel@0 | 4 * |
Daniel@0 | 5 * Copyright 2011, Joe Lambert. |
Daniel@0 | 6 * Free to use under the MIT license. |
Daniel@0 | 7 * http://www.opensource.org/licenses/mit-license.php |
Daniel@0 | 8 */ |
Daniel@0 | 9 |
Daniel@0 | 10 var ScrollFix = function(elem) { |
Daniel@0 | 11 // Variables to track inputs |
Daniel@0 | 12 var startY, startTopScroll; |
Daniel@0 | 13 |
Daniel@0 | 14 elem = elem || document.querySelector(elem); |
Daniel@0 | 15 |
Daniel@0 | 16 // If there is no element, then do nothing |
Daniel@0 | 17 if(!elem) |
Daniel@0 | 18 return; |
Daniel@0 | 19 |
Daniel@0 | 20 // Handle the start of interactions |
Daniel@0 | 21 elem.addEventListener('touchstart', function(event){ |
Daniel@0 | 22 startY = event.touches[0].pageY; |
Daniel@0 | 23 startTopScroll = elem.scrollTop; |
Daniel@0 | 24 |
Daniel@0 | 25 if(startTopScroll <= 0) |
Daniel@0 | 26 elem.scrollTop = 1; |
Daniel@0 | 27 |
Daniel@0 | 28 if(startTopScroll + elem.offsetHeight >= elem.scrollHeight) |
Daniel@0 | 29 elem.scrollTop = elem.scrollHeight - elem.offsetHeight - 1; |
Daniel@0 | 30 }, false); |
Daniel@0 | 31 }; |