'+
5 | '
';
7 | return div;
8 | }
--------------------------------------------------------------------------------
/chapter09/listing9.17.js:
--------------------------------------------------------------------------------
1 | function buildSlide (slideNum) {
2 |
3 | var thisSlide, s, img, scaleFactor = 1, w, h;
4 |
5 | if(!slideData[slideNum] || slideData[slideNum].node){
6 | return false;
7 | }
8 |
9 | thisSlide = slideData[slideNum];
10 | s = slideTemplate(thisSlide);
11 |
12 | img = s.querySelector('div');
13 |
14 | //image is too big! scale it!
15 | if(thisSlide.width > boundingBox[0] || thisSlide.height > boundingBox[1]){
16 |
17 | if(thisSlide.width > thisSlide.height) {
18 | scaleFactor = boundingBox[0]/thisSlide.width;
19 | } else {
20 | scaleFactor = boundingBox[1]/thisSlide.height;
21 | }
22 |
23 | w = Math.round(thisSlide.width * scaleFactor);
24 | h = Math.round(thisSlide.height * scaleFactor);
25 | img.style.height = h + 'px';
26 | img.style.width = w + 'px';
27 |
28 | }else{
29 | img.style.height = thisSlide.height + 'px';
30 | img.style.width = thisSlide.width + 'px';
31 | }
32 |
33 | thisSlide.node = s;
34 | wrapper.appendChild(s);
35 | setPosition(s, boundingBox[0]);
36 | return s;
37 | }
--------------------------------------------------------------------------------
/chapter09/listing9.18.js:
--------------------------------------------------------------------------------
1 | function goTo(slideNum){
2 |
3 | var thisSlide;
4 |
5 | //failure, return to last slide
6 | if(!slideData[slideNum]){
7 | goTo(currentSlide);
8 | }
9 |
10 | if(Math.abs(currentSlide - slideNum) !== 1 &&
11 | slideData[currentSlide] && slideData[currentSlide].node){
12 | //current slide not adjacent to new slide!
13 | setPosition(slideData[currentSlide].node,
14 | (slideNum < currentSlide) ? boundingBox[0] : 0 - boundingBox)
15 | }
16 |
17 | thisSlide = slideData[slideNum];
18 |
19 | //build the adjacent slide
20 | buildSlide(slideNum);
21 | buildSlide(slideNum + 1);
22 | buildSlide(slideNum - 1);
23 |
24 | //animate the slides entering and leavign
25 | if(thisSlide.node){
26 | addTransitions(thisSlide.node);
27 | setPosition(thisSlide.node, 0);
28 | }
29 |
30 | if(slideData[slideNum - 1] && slideData[slideNum-1].node){
31 | addTransitions(slideData[slideNum - 1 ].node);
32 | setPosition( slideData[slideNum - 1 ].node , (0 - boundingBox[0]) );
33 | }
34 |
35 | if(slideData[slideNum + 1] && slideData[slideNum + 1].node){
36 | addTransitions(slideData[slideNum + 1 ].node);
37 | setPosition(slideData[slideNum + 1 ].node, boundingBox[0] );
38 | }
39 |
40 | currentSlide = slideNum;
41 | }
--------------------------------------------------------------------------------
/chapter09/listing9.19.js:
--------------------------------------------------------------------------------
1 | function attachTouchEvents() {
2 |
3 | var bd = document.querySelector('html');
4 | bd.addEventListener('touchmove', handleTouchEvents);
5 | bd.addEventListener('touchstart', handleTouchEvents);
6 | bd.addEventListener('touchend', handleTouchEvents);
7 |
8 | }
--------------------------------------------------------------------------------
/chapter09/listing9.2.css:
--------------------------------------------------------------------------------
1 | body {
2 | font-family: sans-serif;
3 | background: #ccc;
4 | }
5 |
6 | /* gradients */
7 | .switchwrap{
8 | /* cross browser versions omitted for clarity */
9 | background: linear-gradient(to bottom, #cccccc 0%,#eeeeee 100%);
10 | }
11 |
12 | .switchwrap .switch {
13 | /* cross browser versions omitted for clarity */
14 | background: linear-gradient(to bottom, #b8e1fc 0%,#a9d2f3 10%,#90bae4 25%,#90bcea 37%,#90bff0 50%,#6ba8e5 51%,#a2daf5 83%,#bdf3fd 100%);
15 | }
16 |
17 | form {
18 | text-align: center;
19 | width: 150px;
20 | position: relative;
21 | margin:auto;
22 | font-size:18px;
23 | }
24 |
25 | input {
26 | font-size: 18px;
27 | }
28 |
29 | /* the js class makes sure these only work if JavaScript is enabled */
30 | .js .switchwrap {
31 | position: relative;
32 | width: 150px;
33 | height:30px;
34 | margin:auto;
35 | box-shadow: inset 1px 1px 3px #000, inset -1px -1px 3px rgba(0,0,0,0.3);
36 | border-radius: 25px;
37 | overflow: hidden;
38 | }
39 |
40 | .js .switchwrap .switch {
41 | position: absolute;
42 | top:0;
43 | left:0;
44 | font-size: 12px;
45 | width: 28px;
46 | height: 28px;
47 | border: 1px solid #333;
48 | border-radius: 25px;
49 | box-shadow: 1px 1px 2px rgba(0,0,0,0.5), inset 1px 1px 1px rgba(255,255,255,0.6);
50 | }
51 |
52 | .js .switchwrap #power{
53 | position: absolute;
54 | top:0;
55 | left:-1000px;
56 | }
--------------------------------------------------------------------------------
/chapter09/listing9.3.js:
--------------------------------------------------------------------------------
1 | (function() {
2 | var isOn = false;
3 |
4 | var $ = function(selector) {
5 | return document.querySelector(selector);
6 | }
7 |
8 | function turnOn() {
9 | $('#status').innerHTML = 'ON';
10 | isOn = true;
11 | }
12 |
13 | function turnOff() {
14 | $('#status').innerHTML = 'OFF';
15 | isOn = false;
16 | }
17 |
18 | var theSwitch = $('.switch');
19 |
20 | theSwitch.addEventListener('click', function(e) {
21 | if(isOn) {
22 | theSwitch.style.left = '0px';
23 | turnOff();
24 | } else {
25 | theSwitch.style.left = '119px';
26 | turnOn();
27 | }
28 | });
29 |
30 | }());
--------------------------------------------------------------------------------
/chapter09/listing9.4.js:
--------------------------------------------------------------------------------
1 | var TRANSITION_END = 'webkitTransitionEnd',
2 | TRANSITION_CSS = '-webkit-transition',
3 | TRANSFORM_CSS = '-webkit-transform',
4 | TRANSFORM = 'webkitTransform',
5 | TRANSITION = 'webkitTransition';
6 |
7 | //unprefixed
8 | if(document.body.style.transform) {
9 | TRANSITION_END = 'transitionend';
10 | TRANSITION_CSS = 'transition';
11 | TRANSFORM_CSS = 'transform';
12 | TRANSFORM = 'transform';
13 | TRANSITION = 'transition';
14 | }
15 |
16 | var l = $('form').offsetLeft;
17 |
18 | var startLeft;
19 |
20 | function handleTouch(e) {
21 |
22 | switch(e.type) {
23 | case 'touchstart':
24 |
25 | break;
26 | case 'touchmove':
27 |
28 | break;
29 | case 'touchcancel':
30 |
31 | break;
32 | case 'touchend':
33 |
34 | break;
35 | }
36 | }
37 |
38 | theSwitch.addEventListener('touchstart', handleTouch);
39 | theSwitch.addEventListener('touchend', handleTouch);
40 | theSwitch.addEventListener('touchmove', handleTouch);
--------------------------------------------------------------------------------
/chapter09/listing9.5.js:
--------------------------------------------------------------------------------
1 | case 'touchmove':
2 | goTo = (e.touches[0].pageX - l);
3 |
4 | if(goTo < 119 && goTo > 0) {
5 | lastX = e.touches[0].pageX - l;
6 |
7 | //update the position
8 | theSwitch.style[TRANSFORM] = 'translate3d(' +
9 | (e.touches[0].pageX - l) + 'px' + ',0,0)';
10 | }
11 |
12 | if(goTo > 60 && !isOn) {
13 | console.log('turn on');
14 | turnOn();
15 | } else if (goTo < 60 && isOn) {
16 | console.log('turn off');
17 | turnOff();
18 | }
19 |
20 | break;
--------------------------------------------------------------------------------
/chapter09/listing9.6.js:
--------------------------------------------------------------------------------
1 | case 'touchcancel':
2 | //fall through to touchend, logic is the same
3 | case 'touchend':
4 | if(lastX > 60) {
5 | endPoint = 119;
6 | } else {
7 | endPoint = 0;
8 | }
9 |
10 | theSwitch.style[TRANSITION] = TRANSFORM_CSS + ' .1s ease-out';
11 | theSwitch.style[TRANSFORM] = 'translate3d('+endPoint+'px,0,0)';
12 | break;
--------------------------------------------------------------------------------
/chapter09/listing9.7.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/chapter09/listing9.8.css:
--------------------------------------------------------------------------------
1 | html {
2 | background: #f1eee4;
3 | font-family: georgia;
4 | color: #7d7f94;
5 | }
6 |
7 | h1 {
8 | color: #ba4a00;
9 | }
10 |
11 | .welcome {
12 | text-align: center;
13 | text-shadow: 1px 1px 1px #fff;
14 | }
15 |
16 | .welcome h1 {
17 | font-size: 20px;
18 | font-weight: bold;
19 | }
20 |
21 | .welcome {
22 | -webkit-box-sizing: border-box;
23 | -moz-box-sizing: border-box;
24 | box-sizing: border-box;
25 | margin:5px;
26 | padding:10px;
27 | box-shadow: 2px 2px 5px rgba(0,0,0,0.5);
28 | border-radius: 5px;
29 | }
30 |
31 | .carousel {
32 | margin:5px;
33 | }
34 |
35 | .carousel ul li {
36 | height: 70px;
37 | width: 70px;
38 | margin: 5px;
39 | overflow: hidden;
40 | display: block;
41 | float: left;
42 | border-radius: 5px;
43 | box-shadow: 1px 1px 2px rgba(0,0,0,0.5), -1px -1px 2px rgba(255,255,255,1);
44 | }
45 |
46 | .slidelink {
47 | display: inline-block;
48 | height: 75px;
49 | width: 75px;
50 | border: 2px solid red;
51 | }
52 |
53 | .slidewrap {
54 | position: absolute;
55 | width: 100%;
56 | overflow: hidden;
57 | top: 0px;
58 | bottom: 0px;
59 | left:0px;
60 | right:0px;
61 | background: #444;
62 | display: none;
63 | }
64 |
65 | .slide {
66 | width:100%;
67 | height:200px;
68 |
69 | position:absolute;
70 | text-align: center;
71 | top:40px;
72 | left:0px;
73 | }
74 |
75 | .slide div {
76 | display: inline-block;
77 | height:100px;
78 | width:100px;
79 | background-size:100%;
80 | background-repeat:no-repeat;
81 | }
82 |
83 | .slide .caption {
84 | display: block;
85 | position: absolute;
86 | text-align: left;
87 | top: 0px;
88 | left: 0px;
89 | width:150px;
90 | height:25px;
91 | background:rgba(0,0,0,0.5);
92 | }
93 |
94 | .slide .caption a {
95 | color: #fff;
96 | text-decoration: none;
97 | font-family: sans-serif;
98 | }
99 |
100 | .controls {
101 | font-family: arial;
102 | font-size: 28px;
103 | }
104 |
105 | .controls a {
106 | color: #fff;
107 | text-decoration: none;
108 | }
--------------------------------------------------------------------------------
/chapter09/listing9.9.js:
--------------------------------------------------------------------------------
1 | function $(selector) {
2 | return document.querySelector(selector);
3 | }
4 |
5 | var TRANSITION = 'transition',
6 | TRANSFORM = 'transform',
7 | TRANSITION_END = 'transitionend',
8 | TRANSFORM_CSS = 'transform',
9 | TRANSITION_CSS = 'transition';
10 |
11 | if(typeof document.body.style.webkitTransform !== undefined) {
12 | TRANSITION = 'webkitTransition';
13 | TRANSFORM = 'webkitTransform';
14 | TRANSITION_END = 'webkitTransitionEnd';
15 | TRANSFORM_CSS = '-webkit-transform';
16 | TRANSITION_CSS = '-webkit-transition'
17 | }
--------------------------------------------------------------------------------
/chapter10/listing10.01.js:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
22 |
23 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/chapter10/listing10.02.css:
--------------------------------------------------------------------------------
1 | /* Giving all elements border-box makes math easier*/
2 | body * {
3 | -webkit-box-sizing:border-box;
4 | -moz-box-sizing:border-box;
5 | box-sizing:border-box;
6 | }
7 |
8 | /* Pretty fonts */
9 | body {
10 | -webkit-box-sizing:border-box;
11 | -moz-box-sizing:border-box;
12 | box-sizing:border-box;
13 | font-family: sans-serif;
14 | }
15 |
16 | /* This is the part that will move when swiped */
17 | .slide {
18 | /* position: absolute;
19 | overflow: hidden;
20 | top: 0;
21 | left: 0;
22 | margin: 0;*/
23 | }
24 |
25 | .header {
26 | height: 178px;
27 | overflow: hidden;
28 | width: 100%;
29 | top: 0;
30 | left: 0;
31 | position: fixed;
32 | border-bottom: 5px solid black;
33 | background: #fff;
34 | }
35 |
36 | .hero {
37 | display: block;
38 | position: relative;
39 | height: 85%;
40 | width: 100%;
41 | padding-top: 5px;
42 | text-align: center;
43 | background: #000;
44 | }
45 |
46 | .navigation {
47 | position: absolute;
48 | top: 0px;
49 | left: 0px;
50 | width: 100%;
51 | height: 100%;
52 | padding: 0;
53 | margin: 0;
54 | }
55 | .navigation .arrow {
56 | color: #fff;
57 | text-decoration: none;
58 | position: absolute;
59 | height: 100%;
60 | width: 50%;
61 | }
62 | .navigation .arrow span {
63 | display: block;
64 | position: absolute;
65 | top: 40%;
66 | left: 5px;
67 | }
68 | .navigation .next-link {
69 | left: 50%;
70 | }
71 | .navigation .next-link span {
72 | left: auto;
73 | right: 5px;
74 | }
75 |
76 | .hero-img {
77 | display: inline;
78 | max-height: 100%;
79 | max-width: 100%;
80 | }
81 |
82 | .title {
83 | border-top: 4px solid black;
84 | color: black;
85 | height: 40px;
86 | font-size: 24px;
87 | width: 100%;
88 | margin: 0;
89 | text-align: left;
90 | }
91 |
92 | .bd {
93 | width: 100%;
94 | margin-top: 210px;
95 | padding: 0px 20px;
96 | }
97 |
--------------------------------------------------------------------------------
/chapter10/listing10.03.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
19 |
20 |
21 |
22 |
25 |
26 |
--------------------------------------------------------------------------------
/chapter10/listing10.04.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
15 |
16 |
17 |
18 |
23 |
24 |
27 |
--------------------------------------------------------------------------------
/chapter10/listing10.05.css:
--------------------------------------------------------------------------------
1 | @media screen and (orientation: landscape) {
2 | .header {
3 | width: 33%;
4 | height: 110px;
5 | border-bottom: 2px solid black;
6 | }
7 | .header .hero {
8 | background: transparent;
9 | }
10 | .header .title {
11 | height: 34px;
12 | font-size: 14px;
13 | }
14 | .header .arrow span {
15 | top: 10px;
16 | }
17 |
18 | .bd {
19 | width: auto;
20 | margin: 0 10px 0 34%;
21 | padding: 0px;
22 | font-size: 12px;
23 | }
24 | }
--------------------------------------------------------------------------------
/chapter10/listing10.07.js:
--------------------------------------------------------------------------------
1 | var birds = (function() {
2 | var currentBird,
3 | myBirdList,
4 |
5 | currentBird,
6 | myBirdList = birdList;
7 |
8 | var birdMap = {};
9 |
10 | /* Turn the array into a hash table for
11 | faster lookup */
12 | function init() {
13 | for (var i=0, len = myBirdList.length; i < len; i++) {
14 | birdMap[myBirdList[i].name] = i;
15 | }
16 |
17 | setBird(thisBird);
18 | }
19 |
20 | // Find out about the bird at the index
21 | function getInfo(index) {
22 | return myBirdList[index];
23 | }
24 |
25 | function nextBird() {
26 | return myBirdList[currentBird + 1];
27 | }
28 |
29 | //find out about the bird offset items away
30 | function birdAtOffset(offset) {
31 | return myBirdList[currentBird + offset];
32 | }
33 |
34 | //get the current bird
35 | function getThisBird() {
36 | return myBirdList[currentBird];
37 | }
38 |
39 | function prevBird() {
40 | return myBirdList[currentBird - 1];
41 | }
42 |
43 | //set the bird, smart enough to do it from a path,
44 | //a name, or something inbetween
45 | function setBird(birdname) {
46 |
47 | //if it is a path or underscore version
48 | if(birdname.indexOf('_') !== -1) {
49 | //sometimes it might have the /bird/ in front of it
50 | //but this thing won't care
51 | matches = birdname.match(/(?:\/bird\/)?(.+)/);
52 | birdname = matches[1].replace('_', ' ');
53 | }
54 |
55 | currentBird = birdMap[birdname];
56 | }
57 |
58 |
59 | return {
60 | init:init,
61 | nextBird:nextBird,
62 | prevBird:prevBird,
63 | thisBird:getThisBird,
64 | birdAtOffset:birdAtOffset,
65 |
66 | advance:function() {
67 | if(myBirdList[currentBird + 1]) {
68 | currentBird++;
69 | }
70 | },
71 |
72 | setBird:setBird
73 | }
74 | }());
75 |
76 | birds.init();
--------------------------------------------------------------------------------
/chapter10/listing10.08.js:
--------------------------------------------------------------------------------
1 | function getBirdData(path, callback) {
2 | path = path.replace('/bird/', '/fragments/');
3 | var data = modelCache.get(path);
4 |
5 | if(data) {
6 | window.setTimeout(function(){
7 | callback && callback(data);
8 | }, 1);
9 | return;
10 | }
11 |
12 | makeRequest(path, function(xhr) {
13 | modelCache.set(path, xhr.responseText);
14 | callback && callback(xhr.responseText);
15 | })
16 | }
--------------------------------------------------------------------------------
/chapter10/listing10.10.js:
--------------------------------------------------------------------------------
1 | var currentSlide, nextSlide, lastSlide,
2 | moving = false,
3 | THRESHOLD = 100,
4 | nextSlide,
5 | prevSlide;
6 |
7 | function prepare() {
8 | //find out if there are more slides to make
9 | var nextBird = birds.nextBird(),
10 | prevBird = birds.prevBird();
11 |
12 | //make a slide if we can and we haven't already
13 | if(nextBird && (!nextSlide || nextSlide.id !== nextBird)) {
14 | getBirdData(birds.nextBird().path, function(resp) {
15 | nextSlide = new Slide(birds.nextBird().name, resp);
16 | nextSlide.hide();
17 | nextSlide.setLeft(window.innerWidth);
18 | });
19 |
20 | } else if(!nextBird) {
21 | nextSlide = false;
22 | }
23 |
24 | //same for the previous
25 | if(prevBird && (!prevSlide || prevSlide.id != prevBird)){
26 | getBirdData(birds.prevBird().path, function(resp) {
27 | prevSlide = new Slide(birds.prevBird().name, resp);
28 | prevSlide.hide();
29 | prevSlide.setLeft(-window.innerWidth);
30 | });
31 | } else if (!prevBird){
32 | prevSlide = false;
33 | }
34 | }
--------------------------------------------------------------------------------
/chapter10/listing10.11.js:
--------------------------------------------------------------------------------
1 | function goTo(direction) {
2 | moving = true;
3 |
4 | if(direction == 1) {
5 | //when the moving is done, move on to the next slide,
6 | //saving object wehre possible.
7 | currentSlide.onMoveEnd(function(){
8 | //we don't need this anymore
9 | currentSlide.destroy();
10 | prevSlide = currentSlide;
11 | currentSlide = nextSlide;
12 | birds.advance();
13 | prepare();
14 | });
15 |
16 | currentSlide.moveTo(0 - window.innerWidth);
17 | nextSlide.moveTo(0);
18 |
19 | } else {
20 |
21 | currentSlide.onMoveEnd(function(){
22 | currentSlide.destroy();
23 | currentSlide = prevSlide;
24 | nextSlide = currentSlide;
25 | birds.goBack();
26 | prepare();
27 | });
28 |
29 | currentSlide.moveTo(window.innerWidth);
30 | nextSlide.moveTo(window.innerWidth);
31 | prevSlide.moveTo(0);
32 |
33 | }
34 |
35 | }
--------------------------------------------------------------------------------
/chapter10/listing10.12.js:
--------------------------------------------------------------------------------
1 | //The First slide
2 | currentSlide = new Slide(thisBird, false, '.slide');
3 | prepare();
4 |
5 | document.addEventListener('touchstart', handleTouch);
6 | document.addEventListener('touchmove', handleTouch);
7 | document.addEventListener('touchend', handleTouch);
8 |
9 | //prime the cache
10 | birds.birdAtOffset(-2) && getBirdData(birds.birdAtOffset(-2).path);
11 | birds.birdAtOffset(2) && getBirdData(birds.birdAtOffset(2).path);
12 | birds.birdAtOffset(3) && getBirdData(birds.birdAtOffset(3).path);
--------------------------------------------------------------------------------
/chapter10/listing10.13a.js:
--------------------------------------------------------------------------------
1 | window.addEventListener("orientationchange", function(){
2 | if(window.orientation !== 0){
3 | THRESHOLD = 25;
4 | } else {
5 | THRESHOLD = 100;
6 | }
7 | });
--------------------------------------------------------------------------------
/chapter10/listing10.14.js:
--------------------------------------------------------------------------------
1 | var previousOrientation = 0;
2 | function checkOrientation(){
3 | //don't bother changing this if the orientation is the same.
4 | if(window.orientation !== previousOrientation){
5 | previousOrientation = window.orientation;
6 | if(window.orientaiton !== 0) {
7 | THRESHOLD = 25;
8 | } else {
9 | THRESHOLD = 100;
10 | }
11 | }
12 | };
13 |
14 | window.addEventListener("resize", checkOrientation);
15 | window.addEventListener("orientationchange", checkOrientation);
16 |
17 | //as a final fallback, poll.
18 | setInterval(checkOrientation, 2000);
--------------------------------------------------------------------------------
/chapter10/listing10.15.js:
--------------------------------------------------------------------------------
1 | document.addEventListener('MSPointerDown', handleTouch);
2 | document.addEventListener('MSPointerMove', handleTouch);
3 | document.addEventListener('MSPointerCancel', handleTouch);
4 | document.addEventListener('MSPointerUp', handleTouch);
--------------------------------------------------------------------------------
/chapter10/listing10.16.js:
--------------------------------------------------------------------------------
1 | function handleTouch(e) {
2 |
3 | var diff, anchor, direction = 0;
4 |
5 | if(moving) {
6 | return;
7 | }
8 |
9 | //if the target is inside the scrollable area,
10 | //stop handling events
11 | if(getAncestor(e.target, 'DIV').className == 'bd') {
12 | nextSlide.hide();
13 | return;
14 | } else {
15 | e.preventDefault();
16 | }
17 |
18 | switch (e.type) {
19 | case 'MSPointerDown':
20 | case 'touchstart':
21 |
22 | startPoint = e.touches ? e.touches[0].pageX : e.screenX;
23 | currentSlide.cleanTransitions();
24 | if(nextSlide) {
25 | nextSlide.cleanTransitions();
26 | nextSlide.show();
27 | }
28 | if(prevSlide) {
29 | prevSlide.cleanTransitions();
30 | prevSlide.show();
31 | }
32 | lastPos = e.touches ? e.touches[0].pageX : e.screenX;
33 | break;
34 | case 'MSPointerMove':
35 | case 'touchmove':
36 | e.preventDefault();
37 |
38 | diff = e.touches ? e.touches[0].pageX - startPoint : e.screenX - startPoint;
39 |
40 | currentSlide.setLeft(diff);
41 | if(diff > 0) {
42 | prevSlide && prevSlide.setLeft(diff - window.innerWidth);
43 | } else {
44 | nextSlide && nextSlide.setLeft(diff + window.innerWidth);
45 | }
46 | lastPos = e.touches ? e.touches[0].pageX : e.screenX;
47 | break;
48 |
49 | case 'MSPointerUp':
50 | case 'touchcancel':
51 | case 'touchend':
52 | //unchanged
53 | break;
54 | }
55 | }
--------------------------------------------------------------------------------
/chapter10/listing10.6.js:
--------------------------------------------------------------------------------
1 | body * {
2 | -webkit-box-sizing: border-box;
3 | -moz-box-sizing: border-box;
4 | box-sizing: border-box;
5 | }
6 |
7 | body {
8 | font-family: sans-serif;
9 | width: 100%;
10 | -ms-touch-action: none;
11 | }
12 |
13 | .slide {
14 | position: absolute;
15 | overflow: hidden;
16 | top: 0;
17 | left: 0;
18 | width: 100%;
19 | height: 100%;
20 | margin: 0;
21 | }
22 |
23 | .header {
24 | height: 50%;
25 | overflow: hidden;
26 | width: 100%;
27 | top: 0;
28 | left: 0;
29 | position: absolute;
30 | border-bottom: 5px solid black;
31 | background: #fff;
32 | }
33 |
34 | .hero {
35 | display: block;
36 | position: relative;
37 | height: 100%;
38 | width: 100%;
39 | padding-top: 5px;
40 | text-align: center;
41 | }
42 |
43 | .navigation {
44 | position: absolute;
45 | top: 0px;
46 | left: 0px;
47 | width: 100%;
48 | height: 100%;
49 | padding: 0;
50 | margin: 0;
51 | }
52 | .navigation .arrow {
53 | color: #fff;
54 | text-decoration: none;
55 | position: absolute;
56 | height: 100%;
57 | width: 50%;
58 | }
59 | .navigation .arrow span {
60 | display: block;
61 | position: absolute;
62 | top: 40%;
63 | left: 5px;
64 | }
65 | .navigation .next-link {
66 | left: 50%;
67 | }
68 | .navigation .next-link span {
69 | left: auto;
70 | right: 5px;
71 | }
72 |
73 | .hero-img {
74 | display: inline;
75 | max-height: 100%;
76 | max-width: 100%;
77 | }
78 |
79 | .title {
80 | border-top: 4px solid black;
81 | color: black;
82 | height: 40px;
83 | font-size: 24px;
84 | width: 100%;
85 | margin: 0;
86 | text-align: left;
87 | }
88 |
89 | .bd {
90 | width: 100%;
91 | height: 50%;
92 | position: absolute;
93 | overflow: auto;
94 | -webkit-overflow-scrolling: touch;
95 | top: 50%;
96 | padding: 0px 20px;
97 | }
98 |
99 | @media screen and (orientation: landscape) {
100 | .header {
101 | width: 33%;
102 | height: 110px;
103 | border-bottom: 2px solid black;
104 | }
105 | .header .hero {
106 | background: transparent;
107 | }
108 | .header .title {
109 | height: 34px;
110 | font-size: 14px;
111 | }
112 | .header .arrow span {
113 | top: 10px;
114 | }
115 |
116 | .bd {
117 | width: auto;
118 | height: 100%;
119 | top: 0;
120 | margin: 0 10px 0 34%;
121 | padding: 0px;
122 | font-size: 12px;
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/chapter10/ms.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
56 |
--------------------------------------------------------------------------------
/chapter10/quail.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/saw/touch-interfaces/1ea167225cb779ddfecae281abbff628f1c71f0c/chapter10/quail.jpg
--------------------------------------------------------------------------------
/chapter11/README.md:
--------------------------------------------------------------------------------
1 | touchpoints
2 | ===========
3 |
4 | Illustrate touchpoints on any browser with touch support.
--------------------------------------------------------------------------------
/chapter11/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |