//grab the list
var list = document.getElementById("touchlist");
//grab the loading div
var loader = document.getElementById("touchloader");
//keep the state whether the fingers are touched
var isTouched = false;
//keep the state whether a PULL actually went out
var isMoved = false;
//This has the original Top offset (relative to screen) position of the list
var prevY = parseInt(list.offsetTop);
//This has the original Top CSS position of the list
var cssY = list.style.top;
cssY = parseInt(cssY.substring(0, cssY.length - 2));
//Add the start of the touching
list.addEventListener("touchstart", function (e) {
//touch started ? YES
isTouched = true;
//initialize the touched point
prevY = e.changedTouches[0].clientY;
//we use css3 transitions when available for smooth sliding
list.style.transition = "";
e.preventDefault();
}, false);
list.addEventListener("touchend", function (e) {
//on touchup we cancel the touch event
isTouched = false;
//now if the list has moved downwards, it should come up but in a transition
list.style.transition = "top 1s";
if (isMoved) {
//show the loader div
loader.style.display = "block";
loadNewData();
}
list.style.top = cssY + 'px';
isMoved = false;
e.preventDefault();
}, false);
list.addEventListener("touchmove", function (e) {
if (isTouched) {
if (e.changedTouches[0].clientY > prevY) {
//on touchmove, we add the exact amount fingers moved to the top of the list
var change = e.changedTouches[0].clientY - prevY;
//and add it to the style
list.style.top = cssY + change + 'px';
isMoved = true;
}
}
e.preventDefault();
}, false);
//binding mouse events to make this work in desktop browsers as well
list.addEventListener("mousedown", function (e) {
isTouched = true;
prevY = e.clientY;
list.style.transition = "";
e.preventDefault();
},...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.