iPhone Web App: Spin the Bottle
Written by on September 17th, 2008 in Uncategorized.
Tomi Mickelsson has created a fun iPhone Web App called Spin the Bottle. You know, a Web app, not one that has to get into the Apple store.
You can check it out on the iPhone/Touch/emulator and you will see how Tomi uses the iPhone specific APIs, such as:
JAVASCRIPT:
-
-
function startTouch() {
-
setTimeout(hideURLbar, 100);
-
-
document.body.ontouchstart = function(e) {
-
oldangle1 = 0; oldangle2 = 0; oldangle3 = 0;
-
//spinout();
-
cancelspin();
-
}
-
-
document.body.ontouchmove = function(e) {
-
// prevent window scrolling!
-
e.preventDefault();
-
-
if (timer_rot != 0)
-
return;
-
-
var touch = e.touches[0]; // finger 1
-
var dx = centerx - touch.pageX;
-
var dy = centery - touch.pageY;
-
var angle = Math.atan2(dy, dx);
-
-
oldangle3 = angle;
-
oldangle1 = oldangle2;
-
oldangle2 = oldangle3;
-
-
var val = “rotateZ(” + angle + “rad)”;
-
bottle.style.webkitTransform = val;
-
shadow.style.webkitTransform = val;
-
rot = angle;
-
//cancelspin();
-
}
-
document.body.ontouchend = function(e){
-
if (timer_rot == 0) {
-
var val = ((oldangle2 - oldangle1) + (oldangle3 - oldangle2)) / 2;
-
val /= 3;
-
if (val == 0.0)
-
val = rand(0.3)+0.2;
-
else if (Math.abs(val) <0.3)
-
val *= 3;
-
-
//cancelspin();
-
startanim(val);
-
}
-
}
-
}
-
// remove our touch handlers
-
function stopTouch() {
-
document.body.ontouchstart = null;
-
document.body.ontouchmove = null;
-
document.body.ontouchend = null;
-
}
-
Source: Ajaxian » Front Page
Original Article: http://feeds.feedburner.com/~r/ajaxian/~3/395200624/iphone-web-app-spin-the-bottle
