Академический Документы
Профессиональный Документы
Культура Документы
• media elements
<canvas>,<video>,<audio>
web-pages web-applications
design user-interface
Layout/Structure
Web site design
A Simple Web site design
FORMS 2.0
AUDIO/VIDEO
<video>
ctx.fillStyle=“rgba(200,0,0,0.5)”;
ctx.fillRect (30,30,55,50);
html:
<canvas id="graph" width="400" height="400">
this is displayed when the tag is not supported...
</canvas>
javascript:
var g = document.getElementById('graph');
if (g && g.getContext) {
var c = g.getContext('2d');
}
ctx.clearRect(0,0,400,400);
<canvas>
var gr =
ctx.createLinearGradient(0,200,0,400);
gr.addColorStop(0.5, "#ddd");
gr.addColorStop(1, "green");
ctx.fillStyle = gr;
ctx.fillRect(0,0,400,400);
ctx.beginPath();
ctx.strokeStyle = "#000";
ctx.lineWidth = 0.2;
for (i = 0; i<20; i++) {
ctx.moveTo(0, i*20);
ctx.lineTo(400, i*20);
}
ctx.stroke();
ctx.closePath();
ctx.lineWidth = 0.8;
ctx.textBaseline = "bottom";
ctx.font = "64pt Arial";
ctx.strokeStyle = "red";
ctx.strokeText("demo",100,200);
<canvas>
ctx.fillStyle = "orange";
ctx.fillStyle = "#FFA500";
ctx.fillStyle = "rgb(255,165,0)";
ctx.strokeStyle = "rgba(255,0,0,0.5)";
lineWidth = value
lineCap = type
lineJoin = type
miterLimit = value
createLinearGradient(x1,y1,x2,y2)
createRadialGradient(x1,y1,r1,x2,y2,r2)
addColorStop(position, color)
createPattern(image,type)
Images: draw, scale, slice
// Draw frame
ctx.drawImage(document.getElementById('frame'),
0,0);context.stroke();context.closePath();
Transformations
var i = 0;
State: Canvas states are stored on a stack
var sin = Math.sin(Math.PI/6);
save()
var cos = Math.cos(Math.PI/6);
restore()
ctx.translate(200, 200);
translate(x, y)
var c = 0;
rotate(angle)
for (i; i <= 12; i++) {
scale(x, y) c = Math.floor(255 / 12 * i);
transform(m11, m12, m21, m22, dx, dy) ctx.fillStyle = "rgb(" + c + "," + c + "," + c + ")";
http://www.canvasdemos.com/type/applications/
http://code.edspencer.net/Bean/index.html
http://www.xarg.org/project/chrome-experiment/
http://www.canvasdemos.com/2010/05/06/catch-it/
API
Drag and Drop & History API
Navigator.geolcation.getCurrentPosition(
function(position) {
var lat = position.,coords.latitude;
var lan = position.,coords.longiture;
showLocation(lat, lan);
}
);
geolocation
function doLocation() {
if (navigationSupported() ) {
navigator.geolocation.getCurrentPosition(
showPosition,
positionError,
{
enableHighAccuracy:false,
timeout:10000,
maximumAge:300000
}
);
}
}
function showPosition(position) {
var lat = position.coords.latitude;
var lon = position.coords.longitude;
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("location-map"));
var weAreHere = new GLatLng(lat, lon);
map.setCenter(weAreHere, 13);
var marker = new GMarker(weAreHere);
map.addOverlay( marker );
marker.bindInfoWindowHtml("You are here");
map.setUIToDefault();
}
}
WEB-WORKERS
Native apps have threads and processes
Workers provide web apps with a means for concurrency
Can offload heavy computation onto a separate thread so
your app doesn’t block
Run JS in the background without clogging the UI threads
Come in 3 flavors
– Dedicated (think: bound to a single tab)
– Shared (shared among multiple windows in an origin)
– Persistent (run when the browser is “closed”)
WEB Sockets
Allows bi-directional communication between
client and server in a cleaner, more efficient
form than hanging gets (or a series of
XMLHttpRequests)
# force online:
NETWORK:
online-logo.png
# provide fallback
FALLBACK:
images/ images/fallback-image.png
STORAGE
Local Storage
Provides a way to store data client side
Useful for many classes of applications, especially in
conjunction with offline capabilities
2 main APIs provided: a database API (exposing a SQLite
database) and a structured storage api (key/value pairs)
db.transaction(function(tx) {
tx.executeSql('SELECT * FROM MyTable', [],
function(tx, rs) {
for (var i = 0; i < rs.rows.length; ++i) {
var row = rs.rows.item(i);
DoSomething(row['column']);
}
});
});
localStorage / sessionStorage
check
http://caniuse.com
(among others)
can I use ... ?
Use feature detection, not browser detection
if (Modernizr.video) {
// video element is supported
} else {
// fall back
}
Detecting
Using Modernizr - http://www.modernizr.com/
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dive Into HTML5</title>
<script src="modernizr.min.js"></script>
</head>
<body>
...
</body>
</html>
if (Modernizr.canvas) {
// let's draw some shapes!
} else {
// no native canvas support available :(
}
SmartPhone
Apps using
HTML5 & CSS3
jQtouch
jQuery plugin
adds iPhone styling
adds transitions using CSS3 support
<script type="text/javascript"
src="jqtouch/jquery.js"></script>
<script type="text/javascript"
src="jqtouch/jqtouch.js"></script>
<script type="text/javascript">
var jQT = $.jQTouch({
icon: 'logo.png',
statusBar: 'black'
});
</script>
http://jqtouch.com/preview/demos/main/ DEMO
jQtouch page structure
<body>
<div id="home">
<div class="toolbar">
<h1>RaboTransAct</h1>
<a class="button flip" href="#about">About</a>
</div>
<ul class="edgetoedge">
<li class="arrow"><a href="#location-about">Geolocation demo</a></li>
<li class="arrow"><a href="#information">Information</a></li>
</ul>
</div>
<div id="location">
<div class="toolbar">
<h1>Geolocation</h1>
<a class="button back" href="#">Back</a>
</div>
<span id="location-status">Trying to determine location...</span><br/>
<div id="location-map" style="width:300px; height:300px"></div>
</div>
<div id="location-about">
<div class="toolbar">
<h1>Geolocation</h1>
<a class="button back" href="#">Back</a>
<a class="button flip" href="#location">Run demo</a>
</div>
<h1>About geolocation</h1>
preview on desktop
This can now:
DEMOs
Demos
http://www.designzzz.com/html-5-tutorial.html
http://apirocks.com/html5/html5.html
http://jqtouch.com/preview/demos/main/
http://www.canvasdemos.com/
http://codinginparadise.org/projects/svgweb/sa
mples/demo.html
http://codinginparadise.org/projects/svgweb/sa
mples/javascript-
samples/svg_dynamic_fancy.html
CSS3
New Styles
Example: div:nth-child(3) {}
Columns
Multi Column Layout is now provided by CSS3
Animation and Motion
Questions?
Dasharatham Bitla (Dash)
Founder & CEO, BitlaSoft
dash@bitlasoft.com | www.BitlaSoft.com
http://weblog.bitlasoft.com | http://mobilog.bitlasoft.com