CMCC - Le novità introdotte da HTML5

© 2014 - ALCA Società Cooperativa

Advanced HTML5

HTML5 - il tag audio

HTML5 - il tag audio

HTML preview

HTML sourcecode

<audio controls loop>
  <source src="http://www.quackit.com/music/good_enough.mp3" 
    type="audio/mpeg">
  <p>Your browser does not support the audio element.</p>
</audio>

HTML5 - il tag video

HTML5 - il tag video

HTML preview

HTML sourcecode

<video controls loop>
  <source src="http://www.w3schools.com/html/movie.ogg#t=5,9"/>
  <source src="http://www.w3schools.com/html/movie.mp4#t"/>
  <object data="fhttp://www.w3schools.com/html/movie.swf" type="application/x-shockwave-flash">
    <param value="movie.swf" name="movie"/>
  </object>
  <track src="devstories-en.vtt" label="English subtitles"
         kind="subtitles" srclang="en" default></track>
  <p>Your browser does not support the <code>video</code> element.</p>
</video>

<!--
ATTRIBUTI DISPONIBILI:
muted, width, height, autoplay, loop, buffered, controls
-->

HTML5 - il tag canvas

HTML preview

HTML sourcecode

<canvas id="myCanvas"
        width="250"
        height="100"
        style="border:1px solid;">
  Your browser does not support the HTML5 canvas tag.
</canvas>
<script>
  var c = document.getElementById("myCanvas");
  var ctx = c.getContext("2d");
  ctx.fillStyle = "#FF0000";
  ctx.fillRect(0,0,150,75);
</script>

Il formato JSON

Il formato JSON

Il formato JSON

{
  "esempio_hash": {
    "nome": "Domenico",
    "cognome": "Martella"
  },
  "esempio_array_stringhe": [
    "testo1", "test2"
  ],
  "esempio_array_numerico": [
    1, 2, 3, 4
  ]
}

Chart.js

Come si usa:

  1. Si include la libreria nella pagina
  2. Si crea un tag canvas su cui disegnare
  3. Si disegna utilizzando la libreria

Chart.js

Chart.js - Pie chart

HTML preview

HTML sourcecode

<canvas id="myChart" width="310" height="300"></canvas>
<script src="../../res/vendor/chartjs/Chart.js"></script>
<script type="text/javascript">
var data = [
  { value: 30, color:"#FF2A1E" },
  { value : 50, color : "#E85C1B" },
  { value : 100, color : "#FFA01F" }
];

var ctx = document.getElementById("myChart").getContext("2d");
var myNewChart = new Chart(ctx).Pie(data);
</script>

Chart.js - Linear

HTML preview

HTML sourcecode

<canvas id="myChart" width="310" height="300"></canvas>
<script src="../../res/vendor/chartjs/Chart.js"></script>
<script type="text/javascript">
var data = {
  labels : ["January","February","March","April","May","June"],
  datasets : [
    {
      fillColor : "rgba(255,230,0,0.5)",
      strokeColor : "rgba(220,220,220,1)",
      pointColor : "rgba(220,220,220,1)",
      pointStrokeColor : "#fff",
      data : [65,59,90,81,56,55]
    },
    {
      fillColor : "rgba(255,160,31,0.5)",
      strokeColor : "rgba(151,187,205,1)",
      pointColor : "rgba(151,187,205,1)",
      pointStrokeColor : "#fff",
      data : [28,48,40,19,96,27]
    }
  ]
}

var options = {
  //Boolean - Whether to show labels on the scale
  scaleShowLabels : true,
  //String - Scale label font declaration for the scale label
  scaleFontFamily : "'Arial'",
  //Number - Scale label font size in pixels
  scaleFontSize : 11,
  //String - Scale label font colour
  scaleFontColor : "#666",
  ///Boolean - Whether grid lines are shown across the chart
  scaleShowGridLines : true,
  //Boolean - Whether the line is curved between points
  bezierCurve : true,
  //Boolean - Whether to show a dot for each point
  pointDot : true,
  //Boolean - Whether to animate the chart
  animation : true,
  //Number - Number of animation steps
  animationSteps : 60,
}

var ctx = document.getElementById("myChart").getContext("2d");
var myNewChart = new Chart(ctx).Line(data, options);
</script>

Chart.js - Bar chart

HTML preview

HTML sourcecode

<canvas id="myChart" width="310" height="300"></canvas>
<script src="../../res/vendor/chartjs/Chart.js"></script>
<script type="text/javascript">
var data = {
  labels : ["January","February","March","April","May","June"],
  datasets : [
    {
      fillColor : "rgba(255,230,0,0.5)",
      strokeColor : "rgba(220,220,220,1)",
      data : [65,59,90,81,56,55]
    },
    {
      fillColor : "rgba(255,160,31,0.5)",
      strokeColor : "rgba(151,187,205,1)",
      data : [28,48,40,19,96,27]
    }
  ]
}

var options = {
  //Boolean - Whether to show labels on the scale
  scaleShowLabels : true,
  //String - Scale label font declaration for the scale label
  scaleFontFamily : "'Arial'",
  //Number - Scale label font size in pixels
  scaleFontSize : 11,
  //Boolean - If there is a stroke on each bar
  barShowStroke : true,
  //Number - Pixel width of the bar stroke
  barStrokeWidth : 2,
  //Number - Spacing between each of the X value sets
  barValueSpacing : 5,
  //Number - Spacing between data sets within X values
  barDatasetSpacing : 1
}

var ctx = document.getElementById("myChart").getContext("2d");
var myNewChart = new Chart(ctx).Bar(data, options);
</script>

Chart.js - Doughnut chart

HTML preview

HTML sourcecode

<canvas id="myChart" width="310" height="300"></canvas>
<script src="../../res/vendor/chartjs/Chart.js"></script>
<script type="text/javascript">
var data = [
  { value: 30, color:"#F7464A" },
  { value : 50, color : "#E2EAE9" },
  { value : 100, color : "#D4CCC5" },
  { value : 40, color : "#949FB1" },
  { value : 120, color : "#4D5360" }
]

var options = {
  //The percentage of the chart that we cut out of the middle.
  percentageInnerCutout : 50,
  //Boolean - Whether we should animate the chart
  animation : true,
  //Number - Amount of animation steps
  animationSteps : 100,
  //String - Animation easing effect
  animationEasing : "easeOutBounce",
  //Boolean - Whether we animate the rotation of the Doughnut
  animateRotate : true,
  //Boolean - Whether we animate scaling the Doughnut from the centre
  animateScale : false,
}

var ctx = document.getElementById("myChart").getContext("2d");
var myNewChart = new Chart(ctx).Doughnut(data, options);
</script>

HTML5 - il tag math

HTML5 - il tag math

HTML preview

HTML sourcecode

<math>
  <mrow>
    <munderover>
      <mo>&Integral;</mo>
      <mn>0</mn>
      <mi>&infin;</mi>
    </munderover>
    <mi>sin</mi>
    <mo>&InvisibleTimes;</mo>
    <mi>x</mi><mspace width="0.25em" />
    <mo>&PartialD;</mo><mo>&InvisibleTimes;</mo><mi>x</mi>
  </mrow>
</math>

HTML5 - il tag math

HTML preview

HTML sourcecode

<script type="text/javascript"
  src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=MML_HTMLorMML">
</script>
<math>
  <mrow>
    <munderover>
      <mo>&Integral;</mo>
      <mn>0</mn>
      <mi>&infin;</mi>
    </munderover>
    <mi>sin</mi>
    <mo>&InvisibleTimes;</mo>
    <mi>x</mi><mspace width="0.25em" />
    <mo>&PartialD;</mo><mo>&InvisibleTimes;</mo><mi>x</mi>
  </mrow>
</math>

SVG

HTML5 - il tag svg

HTML preview

HTML sourcecode

<svg
  width="744.09448819"
  height="1052.3622047"
  id="svg2"
  version="1.1">
  <rect
    style="fill:#ff6600;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
    id="rect2987"
    width="130"
    height="240"
    x="10"
    y="10" />
</svg>