-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrollPane.html
142 lines (129 loc) · 5.95 KB
/
scrollPane.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>iOS ScrollPane</title>
<link href='http://fonts.googleapis.com/css?family=Lobster' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/style.css" />
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<section id="stage">
<h2>iOS ScrollPane</h2>
<p>CoffeScript, HTML5 & CSS3 Animations</p>
<div id="mask">
<div id="allScreens"></div>
</div>
<ul id="indicators"></ul>
<div id="dock"><ul></ul></div>
</section>
<script src="http://code.jquery.com/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="http://dotmaster.github.com/Touchable-jQuery-Plugin/touchable.js" type="text/javascript"></script>
<script src="http://jashkenas.github.com/coffee-script/extras/coffee-script.js" type="text/javascript"></script>
<script type="text/coffeescript">
class Icon
constructor: (@id, @title) ->
@markup = "<div class='icon' style='background-image:url(img/#{@id}.png)' title='#{@title}'></div>"
class DockIcon extends Icon
constructor: (id, title) ->
super(id, title)
@markup = "<li id='mail'>
<a href='##{@title}'>
<em><span>#{@title}</span></em>
<img src='img/#{@id}.png' alt='#{@title}' />
</a>
</li>"
class Screen
constructor: (icons = [])->
@icons = icons
attachIcons: (icons = [])->
Array.prototype.push.apply(@icons,icons)
generate: ->
markup = []
markup.push(icon.markup) for icon in @icons
"<div class='screen'>#{markup.join('')}</div>"
class Stage
screenWidth: 442
constructor: (icons)->
@currentScreen = 0
@screens = []
num = Math.ceil(icons.length/16)
i = 0
while num--
s = new Screen(icons[i...i+16])
@screens.push(s)
i+=16
addScreensTo: (element)->
@element = $(element)
@element.width(@screens.length*@screenWidth)
for screen in @screens
@element.append(screen.generate())
addIndicatorsTo: (elem) ->
@ul = $(elem)
for screen in @screens
@ul.append('<li>')
@ul.find('li:first').addClass('active');
goTo: (screenNum)->
if @element.is(':animated')
return false
if @currentScreen == screenNum
[from,to] = ['+=15','-=15']
if @currentScreen == 0 || @currentScreen == @screens.length
[from,to] = [to,from]
@element.animate({marginLeft: from},150).animate({marginLeft: to},150)
else
@element.animate({marginLeft:-screenNum*@screenWidth}, => @currentScreen = screenNum)
@ul.find('li').removeClass('active').eq(screenNum).addClass('active');
next: ->
toShow = @currentScreen+1
if toShow == @screens.length
toShow = @screens.length -1
@goTo(toShow)
previous: ->
toShow = @currentScreen-1
if toShow == -1
toShow = 0
@goTo(toShow)
$ ->
allIcons = [
new Icon('garageband', 'Garage Band'), new Icon('icon_burn', 'Burn')
new Icon('candybar', 'Candybar'), new Icon('system', 'System')
new Icon('quiktime', 'Quicktime'), new Icon('postbox', 'Postbox')
new Icon('itunes', 'iTunes'), new Icon('firefox', 'Firefox')
new Icon('icon_imovie', 'iMovie'), new Icon('mail', 'Mail')
new Icon('icon_thunderbird', 'Thunderbird'), new Icon('icon_vorschau', 'Vorschau')
new Icon('icon_skype', 'Skype'), new Icon('icon_jdownloader', 'jDownloader')
new Icon('finder', 'finder'), new Icon('icon_awaken', 'Awaken')
new Icon('icon_transmit', 'Transmit'), new Icon('icon_textedit', 'Text Edit')
new Icon('icon_lastfm', 'lastFm'), new Icon('icon_gruml', 'Gruml')
new Icon('things', 'Things'), new Icon('iphoto', 'iPhoto')
new Icon('coda', 'Coda'), new Icon('icon_chrome', 'Chrome Browser')
new Icon('twitter', 'Twitter'), new Icon('icon_stickies', 'Stickies')
new Icon('safari', 'Safari'), new Icon('trash_full', 'Trash')
new Icon('icon_transmission', 'Transmission'), new Icon('songbird', 'Songbird')
new Icon('icon_opera', 'Opera Browser'), new Icon('icon_ichat', 'iChat')
new Icon('vlc', 'VLC'), new Icon('icon_cyberduck', 'Cyber Duck')
new Icon('icon_box', 'Box')
]
dockIcons = [
new DockIcon('twitter', 'Twitter')
new DockIcon('icon_cyberduck', 'Cyber Duck')
new DockIcon('icon_gruml', 'Gruml')
new DockIcon('icon_vorschau', 'Vorschau')
]
allScreens = $('#allScreens')
allScreens.Touchable();
stage = new Stage(allIcons)
stage.addScreensTo(allScreens)
stage.addIndicatorsTo('#indicators')
allScreens.bind 'touchablemove', (e,touch)->
stage.next() if touch.currentDelta.x < -5
stage.previous() if touch.currentDelta.x > 5
dock = $('#dock ul')
for icon in dockIcons
dock.append(icon.markup)
</script>
</body>
</html>