<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>SitePoint &#187; JavaScript &amp; CSS</title> <atom:link href="http://www.sitepoint.com/category/tech/dhtml-css/feed/" rel="self" type="application/rss+xml" /><link>http://www.sitepoint.com</link> <description>News, opinion, and fresh thinking for web developers and designers. The official podcast of sitepoint.com.</description> <lastBuildDate>Thu, 09 Feb 2012 15:44:53 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.2.1</generator> <item><title>Build Awesome Apps with CSS3 Animations</title><link>http://www.sitepoint.com/build-awesome-apps-with-css3-animations/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=build-awesome-apps-with-css3-animations</link> <comments>http://www.sitepoint.com/build-awesome-apps-with-css3-animations/#comments</comments> <pubDate>Fri, 03 Feb 2012 13:25:28 +0000</pubDate> <dc:creator>David Rousset</dc:creator> <category><![CDATA[CSS Tutorials]]></category> <category><![CDATA[HTML & CSS]]></category> <category><![CDATA[HTML5]]></category> <category><![CDATA[JavaScript & CSS]]></category> <category><![CDATA[Web Tech]]></category> <category><![CDATA[animation]]></category> <category><![CDATA[HTML5 Dev Center]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=51035</guid> <description><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2012/02/feature1-50x50.png" class="attachment-thumbnail wp-post-image" alt="feature" title="feature" />Today’s HTML5 applications can provide awesome experiences thanks partly  to CSS3 specifications like Animations. David Rousset walks you (and a Star Wars AT-AT) through the motions.]]></description> <content:encoded><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2012/02/feature1-50x50.png" class="attachment-thumbnail wp-post-image" alt="feature" title="feature" /><p></p><p>Today’s HTML5 applications can provide awesome experiences thanks to the new CSS3 specifications. One of them is <strong>CSS3 Animations</strong>. It can help you building rich animations on HTML elements. This can provide interesting feedbacks to the users and enables fast &amp; fluid UIs. As those new animations are most of the time hardware accelerated by the GPU, they definitely raise the quality bar of the new generation of HTML5 applications.</p><p>According to the “CSS Animation Module Level 3” specification on the <a
href="http://www.w3.org/TR/css3-animations/">W3C site</a>, CSS3 Animations <em>introduces defined animations, which specify the values that CSS properties will take over a given time interval. This specification is an extension to CSS Transitions</em>.</p><p>As CSS3 Animation is an <strong>extension to CSS3 Transitions</strong>, you should first read the article of my colleague David Catuhe on Transitions here: <a
href="http://blogs.msdn.com/b/eternalcoding/archive/2011/11/01/css3-transitions.aspx">Introduction to CSS3 Transitions</a>.</p><p>We’ll see in this article an interesting demo highlighting the potential of CSS3 animations, how to build simple animations &amp; how to handle fallback in JavaScript:</p><ol
start="1"><li><a
href="http://blogs.msdn.com/b/davrous/archive/2011/12/06/introduction-to-css3-animations.aspx#intro">CSS3 Animations</a></li><li><a
href="http://blogs.msdn.com/b/davrous/archive/2011/12/06/introduction-to-css3-animations.aspx#support">Browsers Support</a></li><li><a
href="http://blogs.msdn.com/b/davrous/archive/2011/12/06/introduction-to-css3-animations.aspx#fallback">CSS3 Animations JavaScript fallback library</a></li><li><a
href="http://blogs.msdn.com/b/davrous/archive/2011/12/06/introduction-to-css3-animations.aspx#conclusion">Conclusion</a></li></ol><p>Let’s first start by quickly demonstrating what CSS3 Animations are. Here is a sample animation of a Star Wars AT-AT which uses CSS3 Animations to animate parts of the transport (and which will fall back to JavaScript if your browser doesn’t support CSS3 Animations):<div>  <script type='text/javascript'>GA_googleFillSlot("InArticle_728x90_1");</script> </div></p><p><iframe
style="border-width: 0px; border-style: solid; border-color: #ffffff;" src="http://david.blob.core.windows.net/html5/css3atat/index.htm" scrolling="no" width="716" height="570"></iframe></p><p>You can test this sample also in a separate window here: <a
title="http://david.blob.core.windows.net/html5/css3atat/index.htm" href="http://david.blob.core.windows.net/html5/css3atat/index.htm">http://david.blob.core.windows.net/html5/css3atat/index.htm</a></p><p><strong><span
style="text-decoration: underline;">Note:</span></strong> this sample has been tested successfully with native animations under IE10 PP3/PP4, Chrome 15, Firefox 8 &amp; iPad 2 and with JS fallback under IE9 desktop &amp; mobile (Windows Phone). For an unknown reason, it behaves in weird way under Opera 11.50 but works fine with the 11.60. Moreover, our lovely blogging platform is most of the time forcing the IE9 rendering engine via a meta tag. To force it back to the IE10 standards mode, press the F12 key and change the value of “Document Mode” back to IE10. Otherwise, view the demo in a separate window.</p><p>This sample is based on the awesome work done by <a
href="http://twitter.com/acalzadilla">Anthony Calzadilla</a>. You can check other incredible demos on his website here: <a
href="http://www.anthonycalzadilla.com/">http://www.anthonycalzadilla.com</a> . I’m a huge fan of the <a
href="http://www.anthonycalzadilla.com/i-twitty-the-fool/">I twitty the fool</a> sample using SVG &amp; CSS3 Animation for instance.</p><h3>CSS3 Animations</h3><h4>Introduction</h4><p>Let’s first review on what you can play to build the animations. CSS3 Animations works basically on the same values as CSS3 Transition.</p><p>Here they are:</p><ul><li><strong>color</strong>: interpolated via red, green, blue and alpha components (treating each as a number, see below)</li><li><strong>length</strong>: interpolated as real numbers.</li><li><strong>percentage</strong>: interpolated as real numbers.</li><li><strong>integer</strong>: interpolated via discrete steps (whole numbers). The interpolation happens in real number space and is converted to an integer using floor().</li><li><strong>number</strong>: interpolated as real (floating point) numbers.</li><li><strong>transform list</strong>: see CSS Transforms specification: <a
href="http://www.w3.org/TR/css3-2d-transforms/">http://www.w3.org/TR/css3-2d-transforms/</a></li><li><strong>rectangle</strong>: interpolated via the x, y, width and height components (treating each as a number).</li><li><strong>visibility</strong>: interpolated via a discrete step. The interpolation happens in real number space between 0 and 1, where 1 is &#8220;visible&#8221; and all other values are &#8220;hidden&#8221;.</li><li><strong>shadow</strong>: interpolated via the color, x, y and blur components (treating them as color and numbers where appropriate). In the case where there are lists of shadows, the shorter list is padded at the end with shadows whose color is transparent and all lengths (x, y, blur) are 0.</li><li><strong>gradient</strong>: interpolated via the positions and colors of each stop. They must have the same type (radial or linear) and same number of stops in order to be animated.</li><li><strong>paint server</strong> (SVG): interpolation is only supported between: gradient to gradient and color to color. They then work as above.</li><li><strong>space-separated list of above</strong>: If the lists have the same number of items, each item in the list is interpolated using the rules above. Otherwise, no interpolation.</li><li><strong>a shorthand property</strong>: If all the parts of a shorthand can be animated, then interpolation is performed as if each property was individually specified.</li></ul><p>And the following properties must be supported for animations:</p><ul><li>background-color (<em>color</em>)</li><li>background-image (<em>only gradients</em>)</li><li>background-position (<em>percentage and length</em>)</li><li>border-bottom-color (<em>color</em>)</li><li>border-bottom-width (<em>length</em>)</li><li>border-color (<em>color</em>)</li><li>border-left-color (<em>color</em>)</li><li>border-left-width (<em>length</em>)</li><li>border-right-color (<em>color</em>)</li><li>border-right-width (<em>length</em>)</li><li>border-spacing (<em>length</em>)</li><li>border-top-color (<em>color</em>)</li><li>border-top-width (<em>length</em>)</li><li>border-width (<em>length</em>)</li><li>bottom (<em>length and percentage</em>)</li><li>color (<em>color</em>)</li><li>crop (<em>rectangle</em>)</li><li>font-size (<em>length and percentage</em>)</li><li>font-weight (<em>number</em>)</li><li>grid-* (<em>various</em>)</li><li>height (<em>length and percentage</em>)</li><li>left (<em>length and percentage</em>)</li><li>letter-spacing (<em>length</em>)</li><li>line-height (<em>number, length and percentage</em>)</li><li>margin-bottom (<em>length</em>)</li><li>margin-left (<em>length</em>)</li><li>margin-right (<em>length</em>)</li><li>margin-top (<em>length</em>)</li><li>max-height (<em>length and percentage</em>)</li><li>max-width (<em>length and percentage</em>)</li><li>min-height (<em>length and percentage</em>)</li><li>min-width (<em>length and percentage</em>)</li><li>opacity (<em>number</em>)</li><li>outline-color (<em>color</em>)</li><li>outline-offset (<em>integer</em>)</li><li>outline-width (<em>length</em>)</li><li>padding-bottom (<em>length</em>)</li><li>padding-left (<em>length</em>)</li><li>padding-right (<em>length</em>)</li><li>padding-top (<em>length</em>)</li><li>right (<em>length and percentage</em>)</li><li>text-indent (<em>length and percentage</em>)</li><li>text-shadow (<em>shadow</em>)</li><li>top (<em>length and percentage</em>)</li><li>vertical-align (<em>keywords, length and percentage</em>)</li><li>visibility (<em>visibility</em>)</li><li>width (<em>length and percentage</em>)</li><li>word-spacing (<em>length and percentage</em>)</li><li>z-index (<em>integer</em>)</li><li>zoom (<em>number</em>)</li></ul><h4>SVG</h4><p>The properties of SVG objects are animatable when they are defined as <strong>animatable:true</strong> in the SVG specification: <a
href="http://www.w3.org/TR/SVG/struct.html">http://www.w3.org/TR/SVG/struct.html</a>. But at the time where this article is written, I didn’t manage to combine CSS3 Animation directly on SVG elements in any of the latest browsers versions. Today’s samples on the web are then doing a little trick: they are embedding SVG resources into different DIV animated by CSS3 like the <a
href="http://www.anthonycalzadilla.com/i-twitty-the-fool/">I twitty the fool</a> sample.</p><h4>Declarations</h4><p>To declare an animation in a CSS file, here is the kind of generic code you’ll need to write:</p><pre>@keyframes name_of_the_animation {
  from {
    property_to_animate: initial_value;
  }
  50% {
    property_to_animate: intermediate_value;
  }
  to {
    property_to_animate: final_value;
  }
}</pre><p>Which could also be written like that:</p><pre>@keyframes name_of_the_animation {
  0% {
    property_to_animate: initial_value;
  }
  50% {
    property_to_animate: intermediate_value;
  }
  100% {
    property_to_animate: final_value;
  }
}</pre><p>This animation definition declares 3 steps 0, 50 &amp; 100%. You should at least set a <strong><em>from</em></strong> (or 0%) and a <strong><em>to</em></strong> (or 100%) steps to build a correct animation (minimum 2 steps thus). Once done, you may add as many keyframes as you’d like between 0 and 100% to handle precisely the various steps of your animations.</p><p>Once the definition is declared, you can affect it to an element using the classical CSS3 selectors and you’ll need also to configure the animation options. Here the kind of generic blocks you’ll see:</p><pre>#id_of_the_html_element {
    animation-name: name_of_the_animation;
    animation-duration: number_of_seconds s;
    animation-iteration-count: number | infinite;
}</pre><p>To better understand, let’s review a real sample. First of all, as the CSS3 Animations specification is still in a draft stage, you’ll need to use the appropriate vendor prefix. Let’s use IE10 as a sample with the –ms prefix then. Let’s now see how the head of our AT-AT is moving.</p><p>Here’s the animation declaration:</p><pre>@-ms-keyframes rotate-skull {
    0% {
        -ms-transform: rotate(0deg)
    }
    25% {
        -ms-transform: rotate(15deg)
    }
    50% {
        -ms-transform: rotate(-5deg)
    }
    55% {
        -ms-transform: rotate(0deg)
    }
    75% {
        -ms-transform: rotate(-10deg)
    }
    100% {
        -ms-transform: rotate(0deg)
    }
}</pre><p>We’ve got 6 steps (0, 25, 50, 55, 75 &amp; 100%) working on the CSS3 2D transform attributes by changing the value of the rotation.</p><p>The animation is then applied via this CSS rule:</p><pre>#skull
{
    -ms-animation-name: rotate-skull;
    -ms-animation-duration: 7s;
    -ms-animation-iteration-count: infinite;
}</pre><p>We’re targeting the <code>&lt;div&gt;</code> element having the “<code>id=<strong>skull</strong></code>” and we’re applying the animation named “<strong><code>rotate-skull</code></strong>” on it. The animation will have to be completed in <strong>7s</strong> and be played an <strong>infinite</strong> number of times.</p><p>Here is the living result if your browser supports CSS3 Animations:</p><p><iframe
style="border-bottom: #ffffff 0px solid; border-left: #ffffff 0px solid; border-top: #ffffff 0px solid; border-right: #ffffff 0px solid" height="200" src="http://david.blob.core.windows.net/html5/css3atat/AnimSkullATAT.htm" width="400" scrolling="no"></iframe></p><p>We could have written this rule in a shorter manner using the animation shorthand property:</p><pre>#skull {
    -ms-animation: rotate-skull 7s infinite;
}</pre><p>The animations will be triggered as soon as a matching rule is applied. You can then play or stop animations simply via <strong>JavaScript</strong> or via CSS3 to play with the <strong>classes affected to a tag</strong>.</p><h4>Non-linear animations</h4><p>The “animation-timing-function” property can be used if you want non-linear animations. You can even mix the type of timing functions during each keyframe.</p><p>Basically, CSS3 animations will use <a
href="http://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B.C3.A9zier_curves">cubic bezier curve</a> to smooth the animation by computing different speed over its duration.</p><p>The following functions are supported:</p><ul><li><em>linear</em>: Constant speed</li><li><em>cubic-bezier</em>: Speed will be computed according to a cubic bezier curve define by two control points : P0 and P1 (so you will have to define 4 values here : P0x, P0y and P1x, P1y.</li><li><em>ease</em>: Speed will be computed with cubic-bezier(0.25, 0.1, 0.25, 1)</li><li><em>ease-in</em>: Speed will be computed with cubic-bezier(0.42, 0, 1, 1)</li><li><em>ease-inout</em>: Speed will be computed with cubic-bezier(0.42, 0, 0.58, 1)</li><li><em>ease-out</em>: Speed will be computed with cubic-bezier(0, 0, 0.58, 1)</li></ul><p>Here is a simulation tool written by <a
href="http://blogs.msdn.com/b/eternalcoding/archive/2011/11/01/css3-transitions.aspx">David Catuhe</a> that uses pure JavaScript to show the impact of each timing function:</p><p><iframe
style="border-bottom: #ffffff 0px solid; border-left: #ffffff 0px solid; border-top: #ffffff 0px solid; border-right: #ffffff 0px solid" height="650" src="http://www.catuhe.com/msdn/transitions/easingfunctions.htm" width="1000"></iframe></p><p><strong><span
style="text-decoration: underline;">Note:</span></strong> this tool uses in-line SVG supported by Firefox, Chrome, Opera 11.60 &amp; IE9/10. It won’t work properly under Opera 11.50 &amp; Safari on iPad thus.</p><p>This is an awesome tool using SVG. You can even play with your mouse on the custom function to edit the curve. If you’d like to know more about this tool, please again have a look to David’s article.</p><p>If your browser supports CSS3 animations, let’s now see a simple demo using <strong>easing functions to animate a canvas tag</strong> containing an animated sprite with CSS3.</p><p>Here is the CSS3 animations code that will be used in this demo:</p><pre>@-ms-keyframes demo {
    from {
    -ms-animation-timing-function: ease;
    -ms-transform: translateX(0px);
    }
    50% {
    -ms-animation-timing-function: ease-in;
    -ms-transform: translateX(300px);
    }
    to {
    -ms-animation-timing-function: ease-inout;
    -ms-transform: translateX(900px);
    }
}
&nbsp;
#testCanvas
{
    -ms-animation-delay: 0s;
    -ms-animation-duration: 6s;
    -ms-animation-iteration-count: infinite;
    -ms-animation-name: demo;
}</pre><p>As well as all the vendor prefixes variations to make sure it works also in Google Chrome &amp; Mozilla Firefox. And here’s the living output:</p><p><iframe
style="border-bottom: #ffffff 0px solid; border-left: #ffffff 0px solid; border-top: #ffffff 0px solid; border-right: #ffffff 0px solid" height="90" src="http://david.blob.core.windows.net/html5/css3animcanvas/sprites.htm" width="1000"></iframe></p><p>If your browser doesn’t support CSS3 Animation but support canvas, the sprite’s running animation should be displayed but the character won’t move through the width of the screen.</p><p><strong><span
style="text-decoration: underline;">Note:</span></strong> if you’d like to know more about canvas and sprites animation, you can have a look to this article: <a
href="http://blogs.msdn.com/b/davrous/archive/2011/07/21/html5-gaming-animating-sprites-in-canvas-with-easeljs.aspx">HTML5 Gaming: animating sprites in Canvas with EaselJS</a></p><h4>Delay</h4><p>The “animation-delay” property simply allows an animation to begin execution some time after it is applied.</p><h4>Events</h4><p>3 <strong>events</strong> could be raised during an animation. They are named “Animation<em>Start</em>”, “Animation<em>End</em>” and “Animation<em>Iteration</em>”. Depending on your browser, the correct name will be for instance:</p><ul><li>Chrome:<em> webkitAnimationEnd</em></li><li>Firefox: <em>mozAnimationEnd</em></li><li>Internet Explorer:<em> MSAnimationEnd</em></li></ul><p>The event will give you the following details:</p><ul><li><em>animationName</em>: name of the animation which raised the event</li><li><em>elapsedTime</em>: the amount of time the animation has been running, in seconds</li></ul><p>Here is an usage sample for IE10:</p><pre>elementToAnimate.addEventListener("MSAnimationEnd", function () {
    alert("the end !");
}, false);</pre><h3>More about CSS3 animations</h3><p>CSS3 animations are really useful for 2 main reasons:</p><ul><li><strong>Hardware acceleration:</strong> CSS3 Animations are most of the time directly handled by the GPU and could produce smoother results. This could then be a very interesting approach for mobile devices.</li><li><strong>Better separation between code and design</strong>: I know there is some debates on this point but with David, we think that a developer shouldn’t be aware of animations or anything related to design as much as possible. In the same way the designer/artist must not be aware of JavaScript. CSS3 offers then this possibility and could let the designers work with their classical tools to generate the appropriate animations on elements, between screens, etc.</li></ul><p>To highlight this importance in performance, the following HTML5 game I wrote using a full frame &lt;canvas&gt;: <a
title="http://blogs.msdn.com/b/davrous/archive/2011/09/09/html5-platformer-the-complete-port-of-the-xna-game-to-lt-canvas-gt-with-easeljs.aspx" href="http://blogs.msdn.com/b/davrous/archive/2011/09/09/html5-platformer-the-complete-port-of-the-xna-game-to-lt-canvas-gt-with-easeljs.aspx">HTML5 Platformer</a> run at 60 fps in IE9/IE10 on my PC but at 10 fps max on a iPad 2. This is because its CPU is much more limited and the iPad is currently not hardware-accelerating &lt;canvas&gt;. Using CSS3 Transitions/Animations to animate several smaller &lt;canvas&gt; elements could provide a huge performance boost for this game. Think about it when you’re targeting mobile devices!</p><h3>Browsers Support</h3><p>Since the Platform Preview 3 of IE10 available in the <a
href="http://msdn.microsoft.com/en-us/windows/apps/br229516">Windows Developer Preview</a>, we’re supporting CSS3 Animations. And as you can see on the following report produced by <a
href="http://caniuse.com/#search=CSS3%20animation">caniuse.com</a>, the CSS3 animations are now supported on a wide range of browsers:</p><p><img
class="alignnone size-full wp-image-51037" title="fig2" src="http://cdn.sitepoint.com/wp-content/uploads/2012/02/fig2.png" alt="browser support" width="761" height="275" /></p><p>But as the specification is not finished yet (<em>working draft</em>), you must use vendor’s prefixes such as –ms-, –moz-, –webkit-, –o- to make a cross-browsers compatible application.</p><p>But the question could be: how to handle browsers that don’t support this new feature?</p><p>First option is to just do nothing. Thanks to the beauty of graceful degradation, you could just let the user only see a static image if you’ve worked correctly. This is for instance the case of these 2 original samples of Anthony: <a
href="http://www.anthonycalzadilla.com/i-twitty-the-fool/">I Twitty the Fool!</a> and <a
href="http://www.anthonycalzadilla.com/css3-ATAT/">Pure CSS3 AT-AT Walker</a> . When watched in IE9, it looks like we only have a static image. When watched in IE10, the very same code shows nice animations. IE10 users will then have an enhanced version while IE9 will still be able to view and use properly the website. The more modern your browser is, the more visual bonus you will have.</p><p>The second option is to detect the feature via a JS library like Modernizr and try to offer the same animation via a JavaScript library that will mimic the animations. This is what we usually call a fallback mechanism. Unfortunately, I haven’t found today a working &amp; complete JS library that could replace CSS3 animations when not supported by the browser.</p><p>I have then written a sample JS library more or less specifically designed for the AT-AT sample.</p><h3>CSS3 Animations JavaScript fallback library</h3><p>Animations are nothing more than a series of transitions separated by a certain duration defined via the keyframes. I’ve then reused the concepts built by David Catuhe in his transitions helper library. I let you reviewing his article to check the base of the concepts behind the code.</p><p>On my side, I’ve added some support to animate the CSS3 2D Transform rotation &amp; translation values and a way to iterate through the keyframes.</p><p>Here is the main part of the library you need to review:</p><pre>// Animation object
// It need the HTML targeted element, the name of the animation, its duration &amp; iteration count and
// the keyframes contained in an array object
// View the animation simply as a sequence of transitions played a certain number of times
ANIMATIONSHELPER.animation = function (target, name, duration, iterationcount, keyframes) {
    // saving the properties values
    this.name = name;
    this.duration = duration;
    this.iterationcount = iterationcount;
    this.target = target;
&nbsp;
    var elapsedtime = 0;
    var keyframeduration = 0;
    var elapsedtime = 0;
&nbsp;
    // Transforming the percentage of each keyframe into duration value
    for (var i = 0; i &lt; keyframes.length; i++) {
        keyframeduration = ((keyframes[i].percentage * duration) / 100) - elapsedtime;
        keyframes[i].duration = keyframeduration;
        elapsedtime += keyframeduration;
    }
&nbsp;
    this.currentTransition = { isPlaying: false };
    this.keyframes = keyframes;
    this.keyframesCount = keyframes.length;
    this.currentKeyFrameIndex = 0;
&nbsp;
    // The nextTransition() function return the next transition to run
    // based on the current keyframe to play
    this.nextTransition = function (keyframe, ease, customEaseP1X, customEaseP1Y, customEaseP2X, customEaseP2Y) {
        var properties = [];
        var finalValues = [];
        var transition;
&nbsp;
        // Compared to the original TRANSITIONSHELPER of David Catuhe
        // We need a specific code to play with the CSS3 2D Transform properties values
        if (keyframe.propertyToAnimate === "transform") {
            for (var i = 0; i &lt; keyframe.transformType.length; i++) {
                properties.push(keyframe.transformType[i].type);
                if (keyframe.transformType[i].type == "rotate") {
                    finalValues.push({ deg: keyframe.transformType[i].value1 });
                }
                else {
                    finalValues.push({ x: keyframe.transformType[i].value1, y: keyframe.transformType[i].value2 });
                }
            }
&nbsp;
            // Create a new transition
            transition = {
                name: this.name + this.currentKeyFrameIndex,
                target: this.target,
                properties: properties,
                finalValues: finalValues,
                originalValues: ANIMATIONSHELPER.extractValues(target.style[ANIMATIONSHELPER.currentTransformProperty], this.name),
                duration: keyframe.duration,
                startDate: (new Date).getTime(),
                currentDate: (new Date).getTime(),
                ease: ease,
                customEaseP1X: customEaseP1X,
                customEaseP2X: customEaseP2X,
                customEaseP1Y: customEaseP1Y,
                customEaseP2Y: customEaseP2Y,
                isPlaying: true,
                type: "transform"
            };
&nbsp;
            return transition;
        }
        // If it's a classic property to animate, we're using more or less the TRANSITIONSHELPER as-is
        else {
            return TRANSITIONSHELPER.transition(this.target, keyframe.propertyToAnimate, keyframe.value, keyframe.duration, TRANSITIONSHELPER.easingFunctions.linear);
        }
    };
&nbsp;
    // each animation object has a tick function
    // that will be called every 17 ms (to target 60 fps)
    // This ticker is monitoring the current state of the transition and
    // create a new transition as soon as the old one is finished/dead
    this.tick = function () {
        if (this.iterationcount &gt; 0) {
            if (!this.currentTransition.isPlaying) {
                this.currentTransition = this.nextTransition(this.keyframes[this.currentKeyFrameIndex], ANIMATIONSHELPER.easingFunctions.linear);
                // We're using our own global ticker only for the 2D transformations
                // Otherwise, we're using the one from the TRANSITIONSHELPER library
                if (this.currentTransition.type === "transform") {
                    ANIMATIONSHELPER.currentTransitions.push(this.currentTransition);
                }
                this.currentKeyFrameIndex++;
&nbsp;
                // We've reached the last keyframe (100%). We're starting back from the beginning
                if (this.currentKeyFrameIndex &gt;= this.keyframesCount) {
                    this.currentKeyFrameIndex = 0;
                    this.iterationcount--;
                }
            }
        }
    };
};</pre><p>The first part of the code is iterating through each keyframe to compute the exact duration specified by each percentage. We’re then defining a <code>nextTransition()</code> function that will dynamically build the next transition to play based on the current index into the keyframes collection. At last, we’ve got a <code>tick()</code> function that will monitor the current state of the transition applied. Once the transition is finished or dead, it asks for the next transition, push it to the stack of transitions to be played and moves the indexes.</p><p>This <code>tick()</code> function is called thanks to this code:</p><pre>ANIMATIONSHELPER.launchAnimation = function (animation) {
    // Launching the tick service if required
    if (ANIMATIONSHELPER.tickIntervalID == 0) {
        ANIMATIONSHELPER.tickIntervalID = setInterval(ANIMATIONSHELPER.tick, 17);
    }
&nbsp;
    // Little closure to launch the tick method on the appropriate animation instance
    setInterval(function () { animation.tick(); }, 17);
};</pre><p>At last, we have this kind of code that helps us building the keyframes:</p><pre>// Object to build a new generic keyframe (not working on the CSS3 2D Transform properties thus)
ANIMATIONSHELPER.keyframe = function (percentage, propertyToAnimate, value) {
    this.percentage = percentage;
    this.propertyToAnimate = propertyToAnimate;
    this.value = value;
};
&nbsp;
//Objects to build specific rotation keyframes
ANIMATIONSHELPER.rotationkeyframe = function (percentage, value) {
    this.percentage = percentage;
    this.propertyToAnimate = "transform";
    this.transformType = [];
    this.transformType.push(new ANIMATIONSHELPER.transformType("rotate", value));
};</pre><p>To highlight its usage, let’s recreate the previous simple CSS3 Animation skull sample with this library :</p><pre>// number of times you'd like the animations to be run
var iterationsNumber = 100;
&nbsp;
var skullElement = document.getElementById("skull");
var keyframes = [];
keyframes.push(new ANIMATIONSHELPER.rotationkeyframe(25, 15));
keyframes.push(new ANIMATIONSHELPER.rotationkeyframe(50, -5));
keyframes.push(new ANIMATIONSHELPER.rotationkeyframe(55, 0));
keyframes.push(new ANIMATIONSHELPER.rotationkeyframe(75, -10));
keyframes.push(new ANIMATIONSHELPER.rotationkeyframe(100, 0));
&nbsp;
var animation1 = new ANIMATIONSHELPER.animation(skullElement, "rotate-skull", 7000,
                            iterationsNumber, keyframes);
&nbsp;
ANIMATIONSHELPER.launchAnimation(animation1, ANIMATIONSHELPER.easingFunctions.linear);</pre><p>And here is the result that will now work in every browser supporting CSS3 2D Transform:</p><p><iframe
style="border-bottom: #ffffff 0px solid; border-left: #ffffff 0px solid; border-top: #ffffff 0px solid; border-right: #ffffff 0px solid" height="200" src="http://david.blob.core.windows.net/html5/css3atat/indexSkullJS.htm" width="400" scrolling="no"></iframe></p><p>At last, the very first sample demonstrated at the beginning of this article uses Modernizr to check the support for CSS3 Animations. If it’s not the case, it loads the code that will mimic the keyframes defined in the file master.css, moz-master.css &amp; ms-master.css :</p><pre>// Checking if CSS3 animations is supported
if (!Modernizr.cssanimations) {
// if so, we can use our JS fallback library
    supportElement.innerHTML = "CSS3 Animations &lt;strong&gt;are not supported&lt;/strong&gt;";
    LoadJSAnimationsFallback();
}
else {
    // if CSS3 animation is supported, we have nothing to do.
    // The *master.css stylesheets will be automatically applied &amp; used.
    supportElement.innerHTML = "CSS3 Animations &lt;strong&gt;are supported&lt;/strong&gt;";
}</pre><p>The <em>LoadJSAnimationsFallback()</em> function is defined into <em>jsfallback-master.js</em> which simply contains all the keyframes declarations and the 19 animations needed to mimic the behavior created by Anthony in pure CSS3. In this approach, the designer then needs to rewrite all rules using the library. Another approach could be to parse one of the CSS file using an XHR call and to create dynamically the JavaScript calls to the library. This needs more work as you almost need to reimplement the CSS3 animations specifications in JavaScript!</p><p>You now have an idea on the way to build a fallback mechanism to support more browsers while starting to use the latest CSS3 specifications.</p><p>You can download the files for the main sample here: <a
title="http://david.blob.core.windows.net/html5/css3atat/CSS3ATATNonMinified.zip" href="http://david.blob.core.windows.net/html5/css3atat/CSS3ATATNonMinified.zip">http://david.blob.core.windows.net/html5/css3atat/CSS3ATATNonMinified.zip</a></p><p>It contains the unminified versions of the animationsHelper.js, transitionsHelper.js, jsfallback-master.js JavaScript files as well as the various CSS3 declinaison files for the main vendors prefixes.</p><h3>Conclusion</h3><p>CSS3 Animations is a powerful technology to push HTML5 applications to a new level. It offers interesting scenarios. Designers could use it to create a new generation of UI screens with smooth &amp; fluid animations without the need of developers. As it’s hardware-accelerated most of the time, developers should also pay attention to this specification. At last, both could collaborate. Designers could work on a series of predefined animations covering most scenarios. Developers could then create JavaScript libraries that will implement those animations. This library could offer in a transparent way 2 implementations: a dynamic generation of CSS3 on the fly or a fallback for older browsers.</p><h3>Going further</h3><ul><li>Article about CSS3 Transitions by David Catuhe: <a
href="http://blogs.msdn.com/b/eternalcoding/archive/2011/11/01/css3-transitions.aspx">Introduction to CSS3 Transitions</a></li><li>CSS3 Animations specifications: <a
title="http://www.w3.org/TR/css3-animations/" href="http://www.w3.org/TR/css3-animations/">http://www.w3.org/TR/css3-animations/</a></li><li>IE Test Drive on CSS3 animations: <a
title="http://ie.microsoft.com/testdrive/Graphics/hands-on-css3/hands-on_animations.htm" href="http://ie.microsoft.com/testdrive/Graphics/hands-on-css3/hands-on_animations.htm">http://ie.microsoft.com/testdrive/Graphics/hands-on-css3/hands-on_animations.htm</a></li></ul><p><strong>Other useful posts:</strong></p><ul><li>Events are relatively limited in the CSS3 Animation spec. Joe Lambert is proposing an interesting solution to trigger events on each keyframe: <a
href="http://blog.joelambert.co.uk/2011/05/20/css-animation-keyframe-events-javascript-solution/">CSS Animation Keyframe Events (Javascript solution)</a></li></ul><div
style="text-align:center;padding-bottom:50px;"><div
style="float:left;padding-left:30px;"> <script>GA_googleFillSlot("Edit_300x100_C");</script> </div><div
style="float:right;padding-right:30px;"> <script>GA_googleFillSlot("Edit_300x100_D");</script> </div></div><div
style="clear:both"></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/build-awesome-apps-with-css3-animations/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>How to Put Your CSS3 on :target</title><link>http://www.sitepoint.com/css3-target-selector/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=css3-target-selector</link> <comments>http://www.sitepoint.com/css3-target-selector/#comments</comments> <pubDate>Mon, 30 Jan 2012 12:56:51 +0000</pubDate> <dc:creator>Craig Buckler</dc:creator> <category><![CDATA[CSS Tutorials]]></category> <category><![CDATA[HTML & CSS]]></category> <category><![CDATA[HTML5]]></category> <category><![CDATA[JavaScript & CSS]]></category> <category><![CDATA[CSS]]></category> <category><![CDATA[CSS3]]></category> <category><![CDATA[HTML5 Dev Center]]></category> <category><![CDATA[HTML5 Tutorials & Articles]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=50855</guid> <description><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2012/01/630-css3-target-50x50.png" class="attachment-thumbnail wp-post-image" alt="630-css3-target" title="630-css3-target" />Craig's latest tutorial looks at the CSS3 :target selector, a powerful pseudo-class hidden in the depths of the W3C specifications which you may have missed...]]></description> <content:encoded><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2012/01/630-css3-target-50x50.png" class="attachment-thumbnail wp-post-image" alt="630-css3-target" title="630-css3-target" /><p></p><p>CSS pseudo-classes which change styles in response to user actions have been with us for many years. You&#8217;ve almost certainly used :hover, :active and :focus; I can <em>(only just)</em> remember the excitement of changing IE4&#8242;s link colors back in 1997.</p><p>CSS3 also introduced :target; a powerful pseudo-class which can reduce the need for scripting in interactive widgets. Consider a page URL such as http://mysite.com/page<strong>#mytarget</strong>; an element with the id &#8220;mytarget&#8221; can have matching :target styles applied.</p><h2>:target Browser Support</h2><p>All modern browsers support :target and you won&#8217;t experience problems with IE9 or most versions of Chrome, Firefox, Safari and Opera. Unfortunately, that still leaves us with the older versions of IE. I wouldn&#8217;t worry too much about IE6 and 7, but <a
href="http://www.sitepoint.com/browser-trends-january-2012/">IE8 remains the world&#8217;s most used browser version</a>. All is not lost, however, since shims such as <a
href="http://selectivizr.com/">selectivizr</a> can add :target support without requiring complex workarounds.</p><h2>A Simple Document :target</h2><p>We&#8217;ve recently been discussing <a
href="http://www.sitepoint.com/how-to-guarantee-client-payment/">website contracts</a>. Generic contract small print such as payment schedules, hosting conditions, cancellation terms, support policies, glossaries etc. could be contained in one or more web pages. The document could grow to a considerable length even if you try and keep it concise!<div>  <script type='text/javascript'>GA_googleFillSlot("InArticle_728x90_1");</script> </div></p><p>Let&#8217;s look at a snippet of the document&#8217;s HTML5 in <em>contract.html</em>:</p><pre><code>
&lt;h1&gt;Website Contract&lt;/h1&gt;
&lt;nav&gt;
	&lt;ul&gt;
		&lt;li&gt;&lt;a href=&quot;#payment&quot;&gt;Payment Schedule&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;#support&quot;&gt;Support &amp;amp; Maintenance&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;#hosting&quot;&gt;Hosting Terms&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;#glossary&quot;&gt;Glossary&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
&lt;/nav&gt;
&lt;article id=&quot;payment&quot;&gt;
&lt;h2&gt;Payment Schedule&lt;/h2&gt;
&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit.&lt;/p&gt;
&lt;/article&gt;
&lt;article id=&quot;support&quot;&gt;
&lt;h2&gt;Support &amp;amp; Maintenance&lt;/h2&gt;
&lt;p&gt;Ut euismod tempor porttitor.&lt;/p&gt;
&lt;/article&gt;
&lt;article id=&quot;hosting&quot;&gt;
&lt;h2&gt;Hosting Terms&lt;/h2&gt;
&lt;p&gt;Suspendisse ac nisl lorem, ut fermentum erat.&lt;/p&gt;
&lt;/article&gt;
&lt;article id=&quot;glossary&quot;&gt;
&lt;h2&gt;Glossary&lt;/h2&gt;
&lt;p&gt;Aenean id nibh eget nisl blandit hendrerit lobortis ac tortor.&lt;/p&gt;
&lt;/article&gt;
</code></pre><p>We can use the :target attribute to highlight active sections, e.g.</p><pre><code>
article:target
{
	background-color: #ffc;
	border: 2px solid #fcc;
}
</code></pre><p>Anyone <a
href="http://blogs.sitepointstatic.com/examples/tech/css3-target/document.html"><strong>viewing the contract</strong></a> can click a navigation menu item to highlight the appropriate section. You can also issue direct links to clients who require specific information, e.g. <a
href="http://blogs.sitepointstatic.com/examples/tech/css3-target/document.html#support"><strong>contract.html#support</strong></a>.</p><p>The :target selector offers further versatility &#8212; it&#8217;s possible to create dynamic effects in HTML5 and CSS without using JavaScript. Further SitePoint articles are coming soon&hellip;</p><div
style="text-align:center;padding-bottom:50px;"><div
style="float:left;padding-left:30px;"> <script>GA_googleFillSlot("Edit_300x100_C");</script> </div><div
style="float:right;padding-right:30px;"> <script>GA_googleFillSlot("Edit_300x100_D");</script> </div></div><div
style="clear:both"></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/css3-target-selector/feed/</wfw:commentRss> <slash:comments>20</slash:comments> </item> <item><title>What can YOU do with 1 Kilobyte of CSS?</title><link>http://www.sitepoint.com/1-kilobyte-css-gallery/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=1-kilobyte-css-gallery</link> <comments>http://www.sitepoint.com/1-kilobyte-css-gallery/#comments</comments> <pubDate>Tue, 24 Jan 2012 18:59:16 +0000</pubDate> <dc:creator>Craig Buckler</dc:creator> <category><![CDATA[HTML & CSS]]></category> <category><![CDATA[HTML5]]></category> <category><![CDATA[JavaScript & CSS]]></category> <category><![CDATA[CSS]]></category> <category><![CDATA[CSS3]]></category> <category><![CDATA[HTML5 Dev Center]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=50658</guid> <description><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2012/01/629-css-1k-50x50.png" class="attachment-thumbnail wp-post-image" alt="629-css-1k" title="629-css-1k" />Craig takes a look at the CSS1K project which hopes to illustrate how clever developers can be with 1 kilobyte of CSS code.]]></description> <content:encoded><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2012/01/629-css-1k-50x50.png" class="attachment-thumbnail wp-post-image" alt="629-css-1k" title="629-css-1k" /><p></p><p>I&#8217;ve been <a
href="http://www.sitepoint.com/5-reasons-to-watch-page-weight/">moaning about bloated web pages</a> for <a
href="http://www.sitepoint.com/page-weight-google-seo/">some</a> <a
href="http://www.sitepoint.com/minimizing-page-weight-matters/">time</a> now. Despite my protests, <a
href="http://www.sitepoint.com/2012-web-predictions/">web page weights are rapidly approaching 1MB</a>.</p><p>The <a
href="http://css1k.com/">CSS1K project</a> illustrates what you can do with a single kilobyte of slim-lined stylesheet code. It&#8217;s been influenced by galleries such as <a
href="http://www.csszengarden.com/">Zen Garden</a> and JavaScript competitions such as <a
href="http://js1k.com/">js1k.com</a> but, to my knowledge, there&#8217;s never been a CSS challenge.</p><p>The rules are simple:</p><ol><li>You must style the HTML5 page at <a
href="http://css1k.com/">css1k.com</a>.</li><li>Submissions must be in a single CSS file up to 1,024 bytes in size (minification is permitted).</li><li>Vendor prefixes do not count toward the total. You should submit non-prefixed code and <a
href="http://css1k.com/">css1k.com</a> will add the browser prefixes for you.</li><li>External resources such as images, fonts and @imports are forbidden. You can&#8217;t use data URIs either &#8212; shame!</li><li>Cross-browser compatibility is preferable, but you can use graceful degradation if necessary.</li><li>Your code must be released under the <a
href="http://www.opensource.org/licenses/mit-license.php">open source MIT license</a>.</li></ol><p>There are a few dozen entries so far. I particularly liked:<div>  <script type='text/javascript'>GA_googleFillSlot("InArticle_728x90_1");</script> </div></p><ul><li><a
href="http://css1k.com/#skewed">Skewed</a> &#8212; clever, although not a great user experience!</li><li><a
href="http://css1k.com/#bbubles">Bbubles</a> &#8212; great demonstration of CSS transitions</li><li><a
href="http://css1k.com/#bookshelf">Bookshelf</a> &#8212; what did you expect?</li><li><a
href="http://css1k.com/#desktop">Desktop</a> &#8212; Windows XP in 1K!</li><li><a
href="http://css1k.com/#geocities">Geocities</a> &#8212; ahh, the nostalgia!</li></ul><p>There are relatively few impressive examples so this is your chance to show off your ninja-like CSS skills! If you decide to post an entry, please leave your link in the comments below&hellip;</p><div
style="text-align:center;padding-bottom:50px;"><div
style="float:left;padding-left:30px;"> <script>GA_googleFillSlot("Edit_300x100_C");</script> </div><div
style="float:right;padding-right:30px;"> <script>GA_googleFillSlot("Edit_300x100_D");</script> </div></div><div
style="clear:both"></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/1-kilobyte-css-gallery/feed/</wfw:commentRss> <slash:comments>9</slash:comments> </item> <item><title>How to Use Character Entities in HTML, CSS and JavaScript</title><link>http://www.sitepoint.com/character-entities-html-css-javascript/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=character-entities-html-css-javascript</link> <comments>http://www.sitepoint.com/character-entities-html-css-javascript/#comments</comments> <pubDate>Sat, 21 Jan 2012 15:48:42 +0000</pubDate> <dc:creator>Craig Buckler</dc:creator> <category><![CDATA[HTML & CSS]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[JavaScript & CSS]]></category> <category><![CDATA[characters]]></category> <category><![CDATA[CSS]]></category> <category><![CDATA[html]]></category> <category><![CDATA[HTML5 Dev Center]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[UTF-8]]></category> <category><![CDATA[xml]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=49599</guid> <description><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2011/12/622-html-entities-50x50.png" class="attachment-thumbnail wp-post-image" alt="622-html-entities" title="622-html-entities" />Craig's useful tutorial explains how you can use UTF-8 characters in HTML, CSS and JavaScript.]]></description> <content:encoded><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2011/12/622-html-entities-50x50.png" class="attachment-thumbnail wp-post-image" alt="622-html-entities" title="622-html-entities" /><p></p><p>You&#8217;ve almost certainly encountered entities in HTML pages. They&#8217;re commonly used for international characters, mathematical operators, shapes, arrows and other symbols. For example:</p><pre><code>
&amp;spades;
&amp;clubs;
&amp;hearts;
&amp;diams;
&amp;copy;
&amp;reg;
</code></pre><p>These map directly to UTF-8 characters. The symbol for PI (&pi;) can either be written as &amp;pi; or its UTF-8 number &#038;#960;. You can look-up popular symbols on the <a
href="http://www.digitalmediaminute.com/reference/entity/">HTML Character Entity Reference</a> to discover their HTML entity code and UTF-8 index number.</p><p>Strictly speaking, it&#8217;s not necessary to use these codes if you&#8217;re serving pages as UTF-8; the default character set for HTML and XML documents. However, there may be occasions when you&#8217;re not using UTF-8, adjacent characters are causing issues, or it&#8217;s difficult to enter a specific symbol on your keyboard. Similarly, you may be using ANSI or another encoding method for CSS and JavaScript files.</p><h2>Entities in CSS</h2><p>Adding content via pseudo elements is increasingly common &#8212; especially if you&#8217;re using <a
href="http://www.sitepoint.com/webfont-icons/">webfont icons</a>. To add any UTF-8 character, you need to find its number and convert that to hexadecimal. For Pi, it&#8217;s 03C0. This can be added within a CSS file using a preceding backslash, e.g.<div>  <script type='text/javascript'>GA_googleFillSlot("InArticle_728x90_1");</script> </div></p><pre><code>
#pi:before
{
	content: &quot;&#092;03C0&quot;;
}
</code></pre><h2>Entities in JavaScript</h2><p>Like CSS, JavaScript requires the UTF-8 number in hexadecimal. In this case, however, it must be escaped using a preceding &#8220;\u&#8221;, e.g.</p><pre><code>
var pi = &quot;\u03C0&quot;;
</code></pre><p>If the character code is 255 or less, you can also use standard JavaScript 2-digit hexadecimal notation, e.g.</p><pre><code>
var copyright = &quot;\xA9&quot;;
</code></pre><p>That&#8217;s all there is to it. Simple solutions, but ones I always forget!</p><div
style="text-align:center;padding-bottom:50px;"><div
style="float:left;padding-left:30px;"> <script>GA_googleFillSlot("Edit_300x100_C");</script> </div><div
style="float:right;padding-right:30px;"> <script>GA_googleFillSlot("Edit_300x100_D");</script> </div></div><div
style="clear:both"></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/character-entities-html-css-javascript/feed/</wfw:commentRss> <slash:comments>9</slash:comments> </item> <item><title>Webfont Icons: an Alternative to Images</title><link>http://www.sitepoint.com/webfont-icons/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=webfont-icons</link> <comments>http://www.sitepoint.com/webfont-icons/#comments</comments> <pubDate>Tue, 17 Jan 2012 16:49:01 +0000</pubDate> <dc:creator>Craig Buckler</dc:creator> <category><![CDATA[CSS Tutorials]]></category> <category><![CDATA[Gems]]></category> <category><![CDATA[HTML & CSS]]></category> <category><![CDATA[HTML5]]></category> <category><![CDATA[JavaScript & CSS]]></category> <category><![CDATA[Web Design Tutorials & Articles]]></category> <category><![CDATA[CSS3]]></category> <category><![CDATA[graphics]]></category> <category><![CDATA[HTML5 Dev Center]]></category> <category><![CDATA[icons]]></category> <category><![CDATA[webfonts]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=49595</guid> <description><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2011/12/621-icon-fonts-50x50.png" class="attachment-thumbnail wp-post-image" alt="621-icon-fonts" title="621-icon-fonts" />Craig's latest tutorial describes how to use webfont icons in your pages and why they have several advantages over images.]]></description> <content:encoded><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2011/12/621-icon-fonts-50x50.png" class="attachment-thumbnail wp-post-image" alt="621-icon-fonts" title="621-icon-fonts" /><p></p><p>Let&#8217;s be honest, creating dozens of tiny icons in a graphics package isn&#8217;t fun. Even when you&#8217;ve gathered a decent set, you end up managing dozens of tiny files or creating image sprites and slicing them in CSS.</p><p>Fortunately, HTML5 provides us with another option: webfonts. A font set can contain graphical icons and character sets. Wingdings is the most well known but free fonts such as <a
href="http://somerandomdude.com/work/iconic/">Iconic</a> can be more useful and provide example HTML and CSS code.</p><p><a
href="http://blogs.sitepointstatic.com/examples/tech/icon-fonts/index.html"><strong>View the webfont icon demonstration page&hellip;</strong></a></p><p>Once you&#8217;ve found or created a suitable font, you&#8217;ll need to convert it to a number of formats to ensure good cross-browser compatibility. The <a
href="http://www.fontsquirrel.com/fontface/generator">@Font-Face Generator at fontsquirrel.com</a> does the hard work for you and supplies a ZIP file containing all the fonts and CSS code. The font is then imported at the top of your CSS file, e.g.</p><pre><code>
@font-face {
	font-family: &quot;IconicStroke&quot;;
	src: url(&quot;iconic_stroke.eot&quot;);
	src: url(&quot;iconic_stroke.woff&quot;) format(&quot;woff&quot;),
	url(&quot;iconic_stroke.ttf&quot;) format(&quot;truetype&quot;),
	url(&quot;iconic_stroke.otf&quot;) format(&quot;opentype&quot;),
	url(&quot;iconic_stroke.svg#iconic&quot;) format(&quot;svg&quot;);
}
</code></pre><p>It&#8217;s possible to add icon characters to your HTML file, such as using an &#8216;r&#8217; for Iconic&#8217;s RSS icon. However, that may confuse people using screen readers so CSS pseudo elements are a safer option, e.g.</p><p>Your HTML:</p><pre><code>
&lt;a href=&quot;rss.xml&quot; class=&quot;rss&quot;&gt;RSS Feed&lt;/a&gt;
</code></pre><p>Your CSS:</p><pre><code>
.rss:before
{
	font-family: &quot;IconicStroke&quot;;
	content: &quot;r&quot;;
}
</code></pre><h2>The Advantages of Webfont Icons</h2><p>Webfonts can be an ideal alternative to graphics:</p><ul><li>fonts can be scaled to any size, use any color and have CSS effects applied</li><li>webfonts offer good cross-browser compatibility and even work in IE6</li><li>a single font file can be more efficient than multiple images</li></ul><h2>The Disadvantages of Webfont Icons</h2><p>Webfonts may not always be appropriate:</p><ul><li>font characters are single-color (although CSS3 effects can help)</li><li>generating fonts is not as easy as PNGs or SVGs</li><li>image file sizes will be smaller if you only require a few icons.</li></ul><p>Overall, there&#8217;s little to dislike about webfont icons and they could cut development time. Have you used them in any of your projects?</p><p><a
href="http://blogs.sitepointstatic.com/examples/tech/icon-fonts/index.html"><strong>View the webfont icon demonstration page&hellip;</strong></a></p><div
style="text-align:center;padding-bottom:50px;"><div
style="float:left;padding-left:30px;"> <script>GA_googleFillSlot("Edit_300x100_C");</script> </div><div
style="float:right;padding-right:30px;"> <script>GA_googleFillSlot("Edit_300x100_D");</script> </div></div><div
style="clear:both"></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/webfont-icons/feed/</wfw:commentRss> <slash:comments>17</slash:comments> </item> <item><title>What&#8217;s New in Firebug 1.9</title><link>http://www.sitepoint.com/firebug-19-new-features/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=firebug-19-new-features</link> <comments>http://www.sitepoint.com/firebug-19-new-features/#comments</comments> <pubDate>Mon, 09 Jan 2012 17:51:17 +0000</pubDate> <dc:creator>Craig Buckler</dc:creator> <category><![CDATA[ajax]]></category> <category><![CDATA[Client Side Coding]]></category> <category><![CDATA[Gems]]></category> <category><![CDATA[HTML5]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[JavaScript & CSS]]></category> <category><![CDATA[plugins]]></category> <category><![CDATA[Reviews]]></category> <category><![CDATA[CSS]]></category> <category><![CDATA[firebug]]></category> <category><![CDATA[firefox]]></category> <category><![CDATA[HTML5 Dev Center]]></category> <category><![CDATA[javascript]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=49944</guid> <description><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2010/12/455-firebug-16.png" class="attachment-thumbnail wp-post-image" alt="455-firebug-16" title="455-firebug-16" />Craig takes a look at the new features in Firebug 1.9, the world's best-known browser development console.]]></description> <content:encoded><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2010/12/455-firebug-16.png" class="attachment-thumbnail wp-post-image" alt="455-firebug-16" title="455-firebug-16" /><p></p><p>Firebug is the world&#8217;s best-known browser development console. All browsers offer decent debugging facilities these days but they all owe a debt of gratitude to Firebug. Even developers who have switched browsers keep Firefox installed because Firebug is so damn good!</p><p>If you have Firebug installed in Firefox 5.0 or greater you should have received version 1.9 during the past few days. If not, head over to <a
href="http://getfirebug.com/">getfirebug.com</a> for information and download links. Here are some of the new gems you&#8217;ll find&hellip;</p><h2>Configurable Docking</h2><p>Until now, Firebug has either appeared at the bottom of the window or in its own pop-out. It&#8217;s now possible to dock it on the top, bottom, left or right of the browser &#8212; which is great if you&#8217;re using a wide-screen monitor.</p><p>To change the position, click the down arrow next to Firebug&#8217;s icon followed by &#8220;Firebug UI Location&#8221;.</p><p><img
src="http://hacks.mozilla.org/wp-content/uploads/2012/01/docking.png" width="500" height="220" alt="Firebug UI location" class="center" /></p><h2>Improved Error Reporting</h2><p>It&#8217;s important to know which JavaScript file and line which caused an error but Firebug can now highlight the exact location of syntax issues.<div>  <script type='text/javascript'>GA_googleFillSlot("InArticle_728x90_1");</script> </div></p><p><img
src="http://hacks.mozilla.org/wp-content/uploads/2012/01/console-errorcolumn.png" width="500" height="127" alt="Firebug syntax errors" class="center" /></p><h2>Copy JSON From Ajax Responses</h2><p>If you&#8217;re implementing any type of Ajax functionality, Firebug&#8217;s essential. It&#8217;s always been possible to view and expand JSON data but you can now copy the whole payload with a right-click.</p><p><img
src="http://hacks.mozilla.org/wp-content/uploads/2012/01/json-copy.png" width="500" height="214" alt="Firebug JSON copy" class="center" /></p><h2>Resend HTTP Requests</h2><p>This is a great new feature: right-click any request shown in the Console or Net panels and hit <strong>Resend</strong> to execute the request again.</p><p><img
src="http://hacks.mozilla.org/wp-content/uploads/2012/01/net-resend.png" width="500" height="223" alt="Firebug resend HTTP request" class="center" /></p><p>It&#8217;s ideal for Ajax debugging since you don&#8217;t need to reload the page or initiate a new request via your application&#8217;s interface.</p><h2>Font Viewer</h2><p>Everyone&#8217;s using web fonts so Firebug now has a preview tooltip whenever you hover over a font name in the style tab.</p><p><img
src="http://hacks.mozilla.org/wp-content/uploads/2012/01/css-fonttooltip.png" width="500" height="134" alt="Firebug font preview" class="center" /></p><p>There&#8217;s also a built-in font viewer within the Net panel whenever a .woff file is downloaded.</p><p><img
src="http://hacks.mozilla.org/wp-content/uploads/2012/01/net-fontviewer.png" width="500" height="127" alt="Firebug font viewer" class="center" /></p><h2>Quick Removal of Elements</h2><p>To quickly remove an item from your page, click the &#8220;Inspect Element&#8221; icon, highlight the element and press the <strong>Delete</strong> button on your keyboard .</p><h2>&hellip;and More</h2><p>You&#8217;ll also find several other features such as the protocol and cached headers shown in the Net panel, adding a watch from the DOM panel, and tooltips on conditional breakpoints and array items.</p><p>Firebug keeps getting better. Have you discovered any great new features?</p><div
style="text-align:center;padding-bottom:50px;"><div
style="float:left;padding-left:30px;"> <script>GA_googleFillSlot("Edit_300x100_C");</script> </div><div
style="float:right;padding-right:30px;"> <script>GA_googleFillSlot("Edit_300x100_D");</script> </div></div><div
style="clear:both"></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/firebug-19-new-features/feed/</wfw:commentRss> <slash:comments>9</slash:comments> </item> <item><title>Introducing the New Cursor Styles in CSS3</title><link>http://www.sitepoint.com/css3-cursor-styles/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=css3-cursor-styles</link> <comments>http://www.sitepoint.com/css3-cursor-styles/#comments</comments> <pubDate>Thu, 05 Jan 2012 18:34:56 +0000</pubDate> <dc:creator>Craig Buckler</dc:creator> <category><![CDATA[CSS Tutorials]]></category> <category><![CDATA[Gems]]></category> <category><![CDATA[HTML & CSS]]></category> <category><![CDATA[JavaScript & CSS]]></category> <category><![CDATA[Tutorial]]></category> <category><![CDATA[CSS]]></category> <category><![CDATA[CSS3]]></category> <category><![CDATA[cursors]]></category> <category><![CDATA[HTML5 Dev Center]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=47764</guid> <description><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2011/11/601-css3-cursor-styles-50x50.png" class="attachment-thumbnail wp-post-image" alt="601-css3-cursor-styles" title="601-css3-cursor-styles" />Craig reveals a selection of new cursor styles which are available in CSS3 and can be used in most modern browsers.]]></description> <content:encoded><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2011/11/601-css3-cursor-styles-50x50.png" class="attachment-thumbnail wp-post-image" alt="601-css3-cursor-styles" title="601-css3-cursor-styles" /><p></p><p>The early days of web development were a thrill as new technologies and techniques were discovered. We experienced a few stagnant years in the middle of last decade but, thanks to HTML5, web development has become exciting again. In particular, CSS3 is evolving rapidly and you&#8217;ll find some interesting gems in the specifications.</p><p>In this article, we&#8217;re going to examine the CSS cursor property which, as you&#8217;d expect, allows you to change the cursor style as the mouse moves over an element. It&#8217;s become increasingly important for interactive web applications&hellip;</p><h2>CSS2 Cursor Styles</h2><p>CSS2 offered relatively few options <em>(hover over any element to see how the cursor changes)</em>:</p><pre style="cursor:auto;margin:1px 0;border: 1px solid #000">cursor: auto</pre><pre style="cursor:inherit;margin:1px 0;border: 1px solid #000">cursor: inherit</pre><pre style="cursor:crosshair;margin:1px 0;border: 1px solid #000">cursor: crosshair</pre><pre style="cursor:default;margin:1px 0;border: 1px solid #000">cursor: default</pre><pre style="cursor:help;margin:1px 0;border: 1px solid #000">cursor: help</pre><pre style="cursor:move;margin:1px 0;border: 1px solid #000">cursor: move</pre><pre style="cursor:pointer;margin:1px 0;border: 1px solid #000">cursor: pointer </pre><pre style="cursor:progress;margin:1px 0;border: 1px solid #000">cursor: progress</pre><pre style="cursor:text;margin:1px 0;border: 1px solid #000">cursor: text</pre><pre style="cursor:wait;margin:1px 0;border: 1px solid #000">cursor: wait</pre><pre style="cursor:e-resize;margin:1px 0;border: 1px solid #000">cursor: e-resize</pre><pre style="cursor:ne-resize;margin:1px 0;border: 1px solid #000">cursor: ne-resize</pre><pre style="cursor:nw-resize;margin:1px 0;border: 1px solid #000">cursor: nw-resize</pre><pre style="cursor:n-resize;margin:1px 0;border: 1px solid #000">cursor: n-resize</pre><pre style="cursor:se-resize;margin:1px 0;border: 1px solid #000">cursor: se-resize</pre><pre style="cursor:sw-resize;margin:1px 0;border: 1px solid #000">cursor: sw-resize</pre><pre style="cursor:s-resize;margin:1px 0;border: 1px solid #000">cursor: s-resize</pre><pre style="cursor:w-resize;margin:1px 0;border: 1px solid #000">cursor: w-resize</pre><h2>CSS3 Cursor Styles</h2><p>We have more styles to choose from in CSS3. These work in IE9 and the latest versions of Firefox, Chrome, Safari and Opera except where indicated:<div>  <script type='text/javascript'>GA_googleFillSlot("InArticle_728x90_1");</script> </div></p><pre style="cursor:none;margin:1px 0;border: 1px solid #000">cursor: none (not IE, Safari, Opera)</pre><pre style="cursor:context-menu;margin:1px 0;border: 1px solid #000">cursor: context-menu (not Firefox, Chrome)</pre><pre style="cursor:cell;margin:1px 0;border: 1px solid #000">cursor: cell (not Safari)</pre><pre style="cursor:vertical-text;margin:1px 0;border: 1px solid #000">cursor: vertical-text</pre><pre style="cursor:alias;margin:1px 0;border: 1px solid #000">cursor: alias (not Safari)</pre><pre style="cursor:copy;margin:1px 0;border: 1px solid #000">cursor: copy (not Safari)</pre><pre style="cursor:no-drop;margin:1px 0;border: 1px solid #000">cursor: no-drop</pre><pre style="cursor:not-allowed;margin:1px 0;border: 1px solid #000">cursor: not-allowed</pre><pre style="cursor:ew-resize;margin:1px 0;border: 1px solid #000">cursor: ew-resize</pre><pre style="cursor:ns-resize;margin:1px 0;border: 1px solid #000">cursor: ns-resize</pre><pre style="cursor:nesw-resize;margin:1px 0;border: 1px solid #000">cursor: nesw-resize</pre><pre style="cursor:nwse-resize;margin:1px 0;border: 1px solid #000">cursor: nwse-resize</pre><pre style="cursor:col-resize;margin:1px 0;border: 1px solid #000">cursor: col-resize</pre><pre style="cursor:row-resize;margin:1px 0;border: 1px solid #000">cursor: row-resize</pre><pre style="cursor:all-scroll;margin:1px 0;border: 1px solid #000">cursor: all-scroll</pre><h2>Browser-Specific Cursors</h2><p>Mozilla and some editions of Chrome and Safari offer a number of vendor-prefixed cursor styles which are likely to become part of the CSS3 specification:</p><pre style="cursor:-webkit-grab;cursor:-moz-grab;margin:1px 0;border: 1px solid #000">cursor: -webkit-grab; cursor: -moz-grab;</pre><pre style="cursor:-webkit-grabbing;cursor:-moz-grabbing;margin:1px 0;border: 1px solid #000">cursor: -webkit-grabbing; cursor: -moz-grabbing;</pre><pre style="cursor:-webkit-zoom-in;cursor:-moz-zoom-in;margin:1px 0;border: 1px solid #000">cursor: -webkit-zoom-in; cursor: -moz-zoom-in;</pre><pre style="cursor:-webkit-zoom-out;cursor:-moz-zoom-out;margin:1px 0;border: 1px solid #000">cursor: -webkit-zoom-out; cursor: -moz-zoom-out;</pre><h2>Creating Your Own Cursor</h2><p>Finally, you can create your own cursor graphic, e.g.</p><pre style="cursor:auto;margin:1px 0;border: 1px solid #000">cursor: url(images/cursor.cur);
cursor: url(images/cursor.png) x y, auto;</pre><p>Note:</p><ol><li>Internet Explorer requires a Windows cursor file (.cur).</li><li>Firefox, Chrome and Safari require an image &#8212; I&#8217;d recommend a 24-bit alpha-transparent PNG.</li><li>Firefox also requires a second non-URL cursor fallback value.</li><li>It&#8217;s not supported in Opera.</li><li>x and y are optional properties in Firefox, Chrome and Safari which define the precise pointer position from the top-left of the graphic. If omitted, 0 0 is assumed.</li></ol><p>Nice, but it sounds like too much effort to me! I&#8217;ll be sticking with the standard cursor styles&hellip;</p><div
style="text-align:center;padding-bottom:50px;"><div
style="float:left;padding-left:30px;"> <script>GA_googleFillSlot("Edit_300x100_C");</script> </div><div
style="float:right;padding-right:30px;"> <script>GA_googleFillSlot("Edit_300x100_D");</script> </div></div><div
style="clear:both"></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/css3-cursor-styles/feed/</wfw:commentRss> <slash:comments>12</slash:comments> </item> <item><title>Creating Drill-down Analytics with FusionCharts, PHP, MySQL and JSON</title><link>http://www.sitepoint.com/creating-drill-down-analytics-with-fusioncharts-php-mysql-and-json/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=creating-drill-down-analytics-with-fusioncharts-php-mysql-and-json</link> <comments>http://www.sitepoint.com/creating-drill-down-analytics-with-fusioncharts-php-mysql-and-json/#comments</comments> <pubDate>Fri, 09 Dec 2011 04:39:12 +0000</pubDate> <dc:creator>Rob Frieman &#38; Michael McCarthy</dc:creator> <category><![CDATA[HTML & CSS]]></category> <category><![CDATA[JavaScript & CSS]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Tutorial]]></category> <category><![CDATA[Web Tech]]></category> <category><![CDATA[fusioncharts]]></category> <category><![CDATA[json]]></category> <category><![CDATA[mysql]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=48445</guid> <description><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2011/12/feature1-50x50.png" class="attachment-thumbnail wp-post-image" alt="feature" title="feature" />FusionCharts lets you configure and deploy multi-level, drill down charts to present data in an attractive, simple interface. Rob Frieman &#038; Michael McCarthy show you how.]]></description> <content:encoded><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2011/12/feature1-50x50.png" class="attachment-thumbnail wp-post-image" alt="feature" title="feature" /><p></p><p>If you can measure it, you can manage it. If you can visualize it too, even better. Businesses and individuals are swimming in data &#8211; from social networks, to budgets, to resource planning we are surrounded by tools that generate data and most of us build applications that generate even more data for ourselves and our clients. It can be a challenge to distill and present the data generated by your (or your client&#8217;s) business in a way that lets them explore the data to answer questions about their business and make decisions in an informed way.</p><p>FusionCharts is a very accessible application that lets you configure and deploy multi-level, drill-down charts to present data in an attractive, simple interface. In this article we&#8217;ll walk through a simple implementation of FusionCharts using PHP, MySQL and JSON &#8211; you can be up and running in no time using your own data.</p><p>When you&#8217;re working with drill-down data, you need to start with data that naturally aggregates into meaningful groups. In this example, we&#8217;re going to use sales volume over time. The time segments will provide the drill-down &#8211; we&#8217;ll start in years and drill down from there, the core data will be sales counts at a particular date. Other examples could be geographic data, or data that rolls up (or down) through categories.<div>  <script type='text/javascript'>GA_googleFillSlot("InArticle_728x90_1");</script> </div></p><h3>Approach and assumptions</h3><p>For this solution, there will be a combination of custom development integrating a self-contained application, the 3D Column chart from FusionCharts. There are almost 3 dozen chart variants to choose from including scatter plot, line graphs, 2D and 3D options, and so on. FusionCharts provides .swf and .js files that are required for the charts to run, you will have to provide the data and the request/response handlers.</p><p>This tutorial assumes you have PHP5 and a mySQL database installed on your web server. A functional understanding of JSON and PHP are required. An understanding of HTML, CSS and JavaScript are also helpful, but less critical for this tutorial. This stack is not required &#8211; what you really need is a data source and a handler that can take http requests, access the data, and format a response.</p><p>For our purposes though we are going to implement this pretty simply so that any request to our php file will have a JSON response containing all of the data we need.</p><table
border="1" cellspacing="0" cellpadding="0"><tbody><tr><td
style="padding: 6px;" valign="top" width="300">Presentation</td><td
style="padding: 6px;" valign="top" width="360"><code>Column3d.swf</code> embedded in <code>chart-json.html</code></td></tr><tr><td
style="padding: 6px;" valign="top" width="300">Application controller and data access</td><td
style="padding: 6px;" valign="top" width="360"><code>linked-chart.php</code> responds with JSON</td></tr><tr><td
style="padding: 6px;" valign="top" width="300">Database</td><td
style="padding: 6px;" valign="top" width="360">&lt;your database&gt;</td></tr></tbody></table><p>So in our example, any request to <code>chart-json.html</code> will result in the client making request for several assets including javascript files and the <code>swf</code>. When the <code>swf</code> loads it will follow the attributes passed to it in order to load the data, making a request to the php application. That app will access the database, retrieve the data, and format the response. The <code>swf</code> will parse the data contained in the JSON file and build our graph.</p><p>Ready to roll? Let&#8217;s do it.</p><h3>Implementing a Linked FusionChart</h3><p>First, download the core FusionChart JavaScript and Flash files <a
href="http://www.fusioncharts.com/download/">here</a>. Follow the installation instructions found in the <code>index.html</code> file, contained in the zip. LinkedCharts is a feature of FusionCharts that allows you to have unlimited drill-down capabilities where users can click on a data plot item and a child chart will be served up either replacing the current chart or spawned to a child window or frame.</p><p>For this tutorial we&#8217;ll focus on these files:</p><ul><li><code>/chart-json.html</code> (<strong><span
style="text-decoration: underline;">Click here for code</span></strong> Contains the markup to display the chart. includes the proprietary FusionChart JavaScript and Flash files. invokes linked-chart.php)</li><li><code>/linked-chart.php</code> (<strong><span
style="text-decoration: underline;">Click here for code</span></strong> php that connects to the mySQL database and outputs the data as JSON)</li><li><code>/FusionCharts.js</code> (<strong>Code found in zip file.</strong> Proprietary FusionChart file that ingests the JSON and injects the data into Column3D.swf)</li><li><code>/Charts/Column3D.swf</code> (<strong>Code found in zip file.</strong> Displays the user interface to make the data pretty)</li></ul><p>First, we&#8217;ll need our data. Since our example will work with data that neatly aggregates into portions of the year, we&#8217;ll just generate data based on timestamps. We can sort it into groups using SQL later.</p><p>SQL to create the database table :</p><pre>CREATE TABLE 'revenue'
(
  'ID' int(10) unsigned NOT NULL AUTO_INCREMENT,
  'Time' timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  PRIMARY KEY ('ID'),
  KEY 'Time' ('Time')
)</pre><p>Fill the table by way of another php script that will generate 10,000 rows of timestamps over two years that can be used as our sales data over time:</p> <code>generate-random-data.php</code><pre>&lt;?php
//Connect to database
$db_host     = 'database-url-goes-here';
$db_database = 'database-name-goes-here';
$db_username = 'database-username-goes-here';
$db_password = 'database-password-here';
if ( !mysql_connect($db_host, $db_username, $db_password))
    die ("Could not connect to the database server.");
if ( !mysql_select_db($db_database))
    die ("Could not select the database.");
//Set variables
$MinTime = strtotime('2010-01-01');
$MaxTime = strtotime('2010-12-12');
$RecordsToInsert = 10000;
//Generate random time and insert records
for($i = 0; $i &lt; $RecordsToInsert; $i++)
{
      $RandomTime = rand($MinTime, $MaxTime);
      mysql_query("INSERT INTO 'revenue' (Time) VALUES
(FROM_UNIXTIME({$RandomTime}))") or die(mysql_error());
}
//Completed
echo "Inserted {$RecordsToInsert} records.";
?&gt;</pre><p>Now let&#8217;s build out the logic layer. This is the heart of the application since it handles requests and manages the retrieval of the data and the formatting of the response. Since it&#8217;s PHP we&#8217;ll be doing a lot in one file: establishing the database connection, gathering the objects we&#8217;ll need using SQL statement, sorting and filtering the responses, and then formatting the response into JSON.</p><p>First we&#8217;ll handle the request and define the params we&#8217;ll accept in the URI:</p><pre>&lt;?php
//Sanitizing the input
$Type  = $_GET['type'];
$Year  = intval($_GET['year']);
$Month = intval($_GET['month']);</pre><p>Next, we&#8217;ll set up the array to handle our values for segmenting the names of the months. Then use case statements based on the param in the request to select and filter the data into the aggregates we want to provide for drill-down &#8211; in this case months and days. The data returned fills the arrays and will be used later in the JSON response sent to the FusionCharts.js calls.</p><pre>//Months Names
$MonthsNames = array(null, 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
//Prepare variables according to type-of-chart
switch($Type)
{
       default:
       case 'monthly':
              $Query = "SELECT MONTH(Time) AS Value, COUNT(*) AS Total FROM 'revenue' WHERE YEAR(Time)={$Year} GROUP BY Value";
              $ResultArray = array_fill(1, 12, 0); // fill the Result array with 0 values for each month
              $ChartHeading = 'Monthly Revenue for the Year: '.$Year;
              $XaxisName = 'Months';
              break;
       case 'daily':
              $Query = "SELECT DAY(Time) AS Value, count(*) AS Total FROM 'revenue' WHERE YEAR(Time)={$Year} AND MONTH(Time)={$Month} GROUP BY Value";
              $ResultArray = array_fill(1, 31, 0);  // fill the Result array with 0 values for each day
              $ChartHeading = 'Daily Revenue for the Month: '.$MonthsNames[$Month].'/'.$Year;
              $XaxisName = 'Days';
              break;
}</pre><p>Build your database connection and retrieve the data</p><pre>//Connect to database
$db_host     = 'database-url-goes-here';
$db_database = 'database-name-goes-here';
$db_username = 'database-username-goes-here';
$db_password = 'database-password-here';
if ( !mysql_connect($db_host, $db_username, $db_password))
    die ("Could not connect to the database server.");
if ( !mysql_select_db($db_database))
    die ("Could not select the database.");
//Query the database
$QueryResult = mysql_query($Query);
//Fetch results in the Result Array
while($Row = mysql_fetch_assoc($QueryResult))
       $ResultArray[$Row['Value']]=$Row['Total'];</pre><p>Now that the data has been retrieved and stored in an array, we&#8217;ll need to format our JSON response. The first section of JSON will contain information that FusionCharts will use for labels. Based on the level, the JSON will contain more or less data &#8211; 12 rows of data for month, and a variable number of rows for daily.</p><p>The key to the drill-down feature is in the &#8216;link&#8217; attribute &#8211; by passing the URI <code>newchart-jsonurl-get-data.php?type=daily&amp;year='.$Year.'&amp;month='.$MonthNumber.'</code> FusionCharts will make the region of data a link and when the user clicks on it the appropriate month of drill-down data will be loaded.</p><p>Here&#8217;s what the php looks like to generate the JSON</p><pre>//Generate json: parent node
$Output = '{"chart":{"caption":"'.$ChartHeading.'","xaxisname":"'.$XaxisName.'","yaxisname":"Revenue"}, "data":[';
//Generate JSON: inner nodes for monthly and daily view
switch($Type)
{
       default:
       case 'monthly':
              foreach($ResultArray as $MonthNumber =&gt; $value) {  // MonthNumber is month number (1-12)
                     $Output .= '{ "value" : "'.$value.'", "label":"'.$MonthsNames[$MonthNumber].'", "link":"newchart-jsonurl-get-data.php?type=daily&amp;year='.$Year.'&amp;month='.$MonthNumber.'" } ';
                     if ($MonthNumber &lt; count($ResultArray)) {
                           $Output .= ',';
                     }
              }
              break;
       case 'daily':
              foreach($ResultArray as $DayNumber =&gt; $value) { // DayNumber is day (1-31)
                     $Output .= '{ "value" : "'.$value.'", "label":"'.$DayNumber.'" } ';
                     if ($DayNumber &lt; count($ResultArray)) {
                           $Output .= ',';
                     }
              }
              break;
}
$Output .= ']}';
//Send output
echo $Output;
?&gt;</pre><p>Finally, we&#8217;ll need that presentation layer and we&#8217;ll create an HTML page that will contain the requests we need and the params we want to pass to the LinkedChart.</p><p>Code for <code>chart-json.html</code> :</p><pre>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>"&gt;
&lt;html&gt;
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Linked FusionChart using PHP, JSON and MySQL&lt;/title&gt;
&lt;script type="text/javascript" src="Charts/FusionCharts.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id="chartContainer"&gt;FusionCharts will load here&lt;/div&gt;
&lt;script type="text/javascript"&gt;
&lt;!--
FusionCharts._fallbackJSChartWhenNoFlash();
var myChart = new FusionCharts("Charts/Column3D.swf", "myChartId", "700", "500", "0", "1");
myChart.setJSONUrl("linked-chart.php?year=2010");
myChart.render("chartContainer");
// --&gt;
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</pre><p>And here&#8217;s the result:</p><p><img
class="alignnone size-full wp-image-49115" title="fig1" src="http://cdn.sitepoint.com/wp-content/uploads/2011/12/fig11.png" alt="fusioncharts" width="598" height="417" /></p><p>FusionCharts expects the link to be URL encoded but you can override this by using an &#8216;unescapelinks&#8217; attribute for your chart. As FusionCharts builds the chart, the links are embedded in the columns allowing users to click on a column and drill down to the next level of data, in this case daily.</p><p><img
class="alignnone size-full wp-image-49116" title="fig2" src="http://cdn.sitepoint.com/wp-content/uploads/2011/12/fig21.png" alt="fusioncharts " width="598" height="416" /></p><p>You can configure the colors and styles and the levels of drill-down are really throttled by the data that you are working with.</p><p>This was a pretty simple example, but you could extend this in a lot of ways. You could make the data accessible via a RESTful interface and add parameters to the URI pattern, for instance. What are some ideas you have? This example is using tabular data, what about drill-down geo-demographic data? Let us know.</p><div
style="text-align:center;padding-bottom:50px;"><div
style="float:left;padding-left:30px;"> <script>GA_googleFillSlot("Edit_300x100_C");</script> </div><div
style="float:right;padding-right:30px;"> <script>GA_googleFillSlot("Edit_300x100_D");</script> </div></div><div
style="clear:both"></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/creating-drill-down-analytics-with-fusioncharts-php-mysql-and-json/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>What’s New in Opera 11.60</title><link>http://www.sitepoint.com/opera-116-new-features/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=opera-116-new-features</link> <comments>http://www.sitepoint.com/opera-116-new-features/#comments</comments> <pubDate>Thu, 08 Dec 2011 11:50:36 +0000</pubDate> <dc:creator>Craig Buckler</dc:creator> <category><![CDATA[Client Side Coding]]></category> <category><![CDATA[Discussion]]></category> <category><![CDATA[HTML5]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[JavaScript & CSS]]></category> <category><![CDATA[Web Tech]]></category> <category><![CDATA[HTML5 Dev Center]]></category> <category><![CDATA[opera]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=49022</guid> <description><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2010/07/363-opera-106-50x50.png" class="attachment-thumbnail wp-post-image" alt="363-opera-106" title="363-opera-106" />Craig discusses the interesting new features for web developers in the latest version of Opera.]]></description> <content:encoded><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2010/07/363-opera-106-50x50.png" class="attachment-thumbnail wp-post-image" alt="363-opera-106" title="363-opera-106" /><p></p><p>Unlike certain browser vendors I could mention, Opera makes an effort to add shiny new features when they release an update. Version 11.60 is no exception although few users will notice changes unless they&#8217;re using:</p><ul><li>Opera&#8217;s built-in email client &#8212; it&#8217;s been redesigned, or</li><li>the address field &#8212; it has a new quick bookmarking/speed-dial star icon</li></ul><p>Apart from various bug fixes, all the exciting enhancements are under the hood in the Presto 2.10 rendering engine. Developers: prepare to tinker&hellip;</p><h2>New HTML5 Parser</h2><p>Opera implements the <a
href="http://dev.w3.org/html5/spec/parsing.html">W3C HTML Parsing specification</a>. It defines a set of parsing rules &#8212; for valid and invalid HTML &#8212; to ensure all browsers produce the same DOM. This will improve website rendering compatibility although we&#8217;ll need to wait until all vendors follow suit.</p><h2>ECMAScript 5.1 Support</h2><p>Opera 11.60 has full support for the <a
href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">ECMAScript 5.1 specification</a>.</p><h2>Microdata DOM API</h2><p>Microdata attributes such as itemprop and itemscope can be queried using JavaScript. For example, assume a page contains contact details defined using the <a
href="http://schema.org/Person">Schema.org person definition</a>:<div>  <script type='text/javascript'>GA_googleFillSlot("InArticle_728x90_1");</script> </div></p><pre><code>
&lt;div itemscope itemtype=&quot;http://schema.org/Person&quot;&gt;
	&lt;p itemprop=&quot;name&quot;&gt;Craig Buckler&lt;/p&gt;
	&lt;p&gt;URL: &lt;a href=&quot;http://www.sitepoint.com/author/craig-buckler/&quot; itemprop=&quot;url&quot;&gt;http://www.sitepoint.com/author/craig-buckler/&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
</code></pre><p>We can interrogate this data using JavaScript:</p><pre><code>
// fetch the first person in document
var person = document.getItems(&quot;http://schema.org/Person&quot;)[0];
// show first name defined
alert(&quot;This article was written by &quot; + person.properties[&quot;name&quot;][0].textContent);
</code></pre><h2>CSS rem Units</h2><p>CSS <a
href="http://www.w3.org/TR/css3-values/#rem-unit">rem</a> units calculate the size of a font relative to the root rather than containing elements. The property can be used in CSS or SVG.</p><h2>Radial Gradients</h2><p>Opera now offers <a
href="http://www.w3.org/TR/2011/WD-css3-images-20110217/#radial-gradients">radial gradient</a> and <a
href="http://www.w3.org/TR/css3-images/#repeating-gradients">repeated-radial-gradient</a> to supplement <a
href="http://www.w3.org/TR/2011/WD-css3-images-20110217/#linear-gradients">linear gradient</a> support. The syntax:</p><pre><code>-o-radial-gradient(position, size and shape, color stops);</code></pre><p>for example:</p><pre><code>-o-radial-gradient(50% 50%, 50px 50px, #000, #fff)</code></pre><h2>CSS4 image-rendering Property</h2><p>This property specifies which scaling algorithms should be used for images, backgrounds, canvas elements, and border images, e.g. crisp-edges, optimize-contrast, nearest-neighbor, optimizespeed, optimizequality etc.</p><h2>Better HTML5 &lt;audio&gt; and &lt;video&gt; Support</h2><p>The following attributes/properties have been implemented:</p><ul><li><strong>preload</strong> &#8212; can be set to &#8220;none&#8221; (minimizes server traffic), &#8220;metadata&#8221; (permits fetching of track lists, durations, etc.) or &#8220;automatic&#8221; (can optimistically download the entire media resource).</li><li><strong>buffered</strong> &#8212; the time range of the media</li><li><strong>seekable</strong> &#8212; the seekable time range for the media</li><li><strong>muted</strong> &#8212; mutes audio output</li></ul><h2>Custom Protocol and Content Handlers</h2><p>You&#8217;ve probably used &#8220;mailto:email@address.com&#8221; or &#8220;tel:01-234-567890&#8243; in links to launch default email clients or telephony applications. Opera now supports the new <code>navigator.registerProtocolHandler</code> and <code>navigator.registerContentHandler</code> objects which allows you to create your own protocols and define handlers. For more information, refer to this <a
href="http://dev.opera.com/articles/view/html5-custom-protocol-and-content-handlers/">DEV.OPERA article</a>.</p><h2>DOM4 Events</h2><p>Like recent webkit builds, Opera 11.60 allows you to use the following <a
href="http://www.w3.org/TR/domcore/">DOM4 APIs</a>:</p><ol><li>synthetic events: fire a UI event from code, e.g. pressing a key, focusing on an input field, moving the mouse over an element, etc.</li><li>custom events: defining your own event types, e.g. a &#8220;die&#8221; event when a game character is shot.</li></ol><h2>Speculative Parsing</h2><p>Under normal circumstances, browsers delay downloads and rendering until loaded scripts have been executed. Speculative parsing continues to load resources such as images and CSS files in readiness for rendering &#8212; this can boost performance on script-heavy pages.</p><h2>Graceful XML Failure</h2><p>Rather than show an <em>&#8220;XML parsing failed&#8221;</em> error, Opera will now attempt to render badly-formatted XML (XHTML) documents as HTML &#8212; even when they&#8217;re served with the application/xhtml+xml MIME type. While this will fix many rendering problems, you can switch it off in <a
href="config#UserPrefs|AutomaticallyreparseXHTMLwithparsingerrorsasHTML">Opera&#8217;s config panel</a>.</p><p>Even better for those feeling festive, <a
href="http://www.youtube.com/watch?v=4TlPU0QWv6g">Bruce Lawson has sung a Christmas Carol about the changes</a>.</p><p>Opera 11.60 is available for most platforms at <a
href="http://www.opera.com/">opera.com</a>.</p><div
style="text-align:center;padding-bottom:50px;"><div
style="float:left;padding-left:30px;"> <script>GA_googleFillSlot("Edit_300x100_C");</script> </div><div
style="float:right;padding-right:30px;"> <script>GA_googleFillSlot("Edit_300x100_D");</script> </div></div><div
style="clear:both"></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/opera-116-new-features/feed/</wfw:commentRss> <slash:comments>10</slash:comments> </item> <item><title>5 Tips for More Efficient jQuery Selectors</title><link>http://www.sitepoint.com/efficient-jquery-selectors/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=efficient-jquery-selectors</link> <comments>http://www.sitepoint.com/efficient-jquery-selectors/#comments</comments> <pubDate>Fri, 25 Nov 2011 07:37:29 +0000</pubDate> <dc:creator>Craig Buckler</dc:creator> <category><![CDATA[Best Practices]]></category> <category><![CDATA[HTML & CSS]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[JavaScript & Ajax Tutorials]]></category> <category><![CDATA[JavaScript & CSS]]></category> <category><![CDATA[jQuery]]></category> <category><![CDATA[HTML5 Dev Center]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[jQuery Tutorials & Articles]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=47760</guid> <description><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2010/10/435-jquery-143.jpg" class="attachment-thumbnail wp-post-image" alt="435-jquery-143" title="435-jquery-143" />Inefficient jQuery selectors can have an adverse effect on the performance of your web application. Craig provides five tips to help you write efficient selector queries.]]></description> <content:encoded><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2010/10/435-jquery-143.jpg" class="attachment-thumbnail wp-post-image" alt="435-jquery-143" title="435-jquery-143" /><p></p><p>As the name implies, jQuery focuses on queries. The core of the library allows you to find DOM elements using CSS selector syntax and run methods on that collection.</p><p>jQuery uses native browser API methods to retrieve DOM collections. Newer browsers support getElementsByClassName, querySelector and querySelectorAll which parses CSS syntax. However, older browsers only offer getElementById and getElementByTagName. In the worst scenarios, <a
href="http://sizzlejs.com/">jQuery&#8217;s Sizzle engine</a> must parse the selector string and hunt for matching elements.</p><p>Here are five tips which could help you optimize your jQuery selectors&hellip;</p><h2>1. Use an ID if Possible</h2><p>HTML ID attributes are unique in every page and even older browsers can locate a single element very quickly:</p><pre><code>
$("#myelement");
</code></pre><h2>2. Avoid Selecting by Class Only</h2><p>The following class selector will run quickly in modern browsers:</p><pre><code>
$(".myclass");
</code></pre><p>Unfortunately, in older browser such as IE6/7 and Firefox 2, jQuery must examine every element on the page to determine whether &#8220;myclass&#8221; has been applied.</p><p>The selector will be more efficient if we qualify it with a tag name, e.g.</p><pre><code>
$("div.myclass");
</code></pre><p>jQuery can now restrict the search to DIV elements only.<div>  <script type='text/javascript'>GA_googleFillSlot("InArticle_728x90_1");</script> </div></p><h2>3. Keep it Simple!</h2><p>Avoid overly complex selectors. Unless you have an incredibly complex HTML document, it&#8217;s rare you&#8217;ll need any more than two or three qualifiers.</p><p>Consider the following complex selector:</p><pre><code>
$("body #page:first-child article.main p#intro em");
</code></pre><p>p#intro must be unique so the selector can be simplified:</p><pre><code>
$("p#intro em");
</code></pre><h2>4. Increase Specificity from Left to Right</h2><p>A little knowledge of jQuery&#8217;s selector engine is useful. It works from the last selector first so, in older browsers, a query such as:</p><pre><code>
$("p#intro em");
</code></pre><p>loads every em element into an array. It then works up the parents of each node and rejects those where p#intro cannot be found. The query will be particularly inefficient if you have hundreds of <code>em</code> tags on the page.</p><p>Depending on your document, the query can be optimized by retrieving the best-qualified selector first. It can then be used as a starting point for child selectors, e.g.</p><pre><code>
$("em", $("p#intro")); // or
$("p#intro").find("em");
</code></pre><h2>5. Avoid Selector Repetition</h2><p>It&#8217;s rarely necessary to use the same selector twice. The following code selects every <code>p</code> tag three times:</p><pre><code>
$("p").css("color", "blue");
$("p").css("font-size", "1.2em");
$("p").text("Text changed!");
</code></pre><p>Remember jQuery offers chaining; multiple methods can be applied to the same collection. Therefore, the same code can be re-written so it applies to a single selector:</p><pre><code>
$("p").css({ "color": "blue", "font-size": "1.2em"}).text("Text changed!");
</code></pre><p>You should cache the jQuery object in a variable if you need to use the same set of elements multiple times, e.g.</p><pre><code>
var $p = $("p");
$p.css("color", "blue");
$p.text("Text changed!");
</code></pre><p>Unlike standard DOM collections, <a
href="http://www.sitepoint.com/javascript-vs-jquery-html-collections/">jQuery collections aren&#8217;t live</a> and the object is not updated when paragraph tags are added or removed from the document. You can code around this restriction by creating a DOM collection and passing it to the jQuery function when it&#8217;s required, e.g.</p><pre><code>
var p = document.getElementByTagName("p");
$(p).css("color", "blue");
// update the DOM
$(p).text("Text changed!");
</code></pre><p>Do you have any further jQuery selector optimization tips?</p><div
style="text-align:center;padding-bottom:50px;"><div
style="float:left;padding-left:30px;"> <script>GA_googleFillSlot("Edit_300x100_C");</script> </div><div
style="float:right;padding-right:30px;"> <script>GA_googleFillSlot("Edit_300x100_D");</script> </div></div><div
style="clear:both"></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/efficient-jquery-selectors/feed/</wfw:commentRss> <slash:comments>11</slash:comments> </item> <item><title>jQuery Mobile 1.0 Final Released</title><link>http://www.sitepoint.com/jquery-mobile-1-released/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=jquery-mobile-1-released</link> <comments>http://www.sitepoint.com/jquery-mobile-1-released/#comments</comments> <pubDate>Sat, 19 Nov 2011 09:22:26 +0000</pubDate> <dc:creator>Craig Buckler</dc:creator> <category><![CDATA[Android]]></category> <category><![CDATA[Android Discussion]]></category> <category><![CDATA[Apple]]></category> <category><![CDATA[Build Mobile]]></category> <category><![CDATA[CSS Tutorials]]></category> <category><![CDATA[HTML & XHTML Tutorials]]></category> <category><![CDATA[HTML5]]></category> <category><![CDATA[iOS]]></category> <category><![CDATA[iOS Discussion]]></category> <category><![CDATA[JavaScript & Ajax Tutorials]]></category> <category><![CDATA[JavaScript & CSS]]></category> <category><![CDATA[jQuery]]></category> <category><![CDATA[Mobile]]></category> <category><![CDATA[Mobile Design]]></category> <category><![CDATA[Mobile Web Dev]]></category> <category><![CDATA[Mobile Web Development]]></category> <category><![CDATA[Mobile Web Tutorials]]></category> <category><![CDATA[WebOS]]></category> <category><![CDATA[Windows]]></category> <category><![CDATA[HTML5 Dev Center]]></category> <category><![CDATA[jQuery Tutorials & Articles]]></category> <category><![CDATA[Mobile Tutorials & Articles]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=48219</guid> <description><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2011/11/607-jquery-mobile-50x50.png" class="attachment-thumbnail wp-post-image" alt="607-jquery-mobile" title="607-jquery-mobile" />Craig takes a look at final jQuery Mobile 1.0 release and illustrates how it could help you build your next mobile application.]]></description> <content:encoded><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2011/11/607-jquery-mobile-50x50.png" class="attachment-thumbnail wp-post-image" alt="607-jquery-mobile" title="607-jquery-mobile" /><p></p><p>Following a year of thorough testing and debugging by 125 contributors, the final gold version of <a
href="http://jquerymobile.com/">jQuery Mobile</a> has been released. If you&#8217;re developing mobile applications for iOS, Android, Blackberry, Bada, Windows, WebOS, Symbian or MeeGo, you should certainly investigate what jQuery Mobile offers.</p><p>Before we go any further, I should clear up some confusion. Despite the name, jQuery Mobile is <em>not</em> jQuery for mobiles! It&#8217;s an interface framework which requires the standard jQuery core (1.6.4 is supported at this time). It could be likened to <a
href="http://jqueryui.com/">jQuery UI</a> for mobile devices or, more accurately, projects such as <a
href="http://www.sencha.com/products/touch/">Sencha Touch</a>.</p><p><img
src="http://blogs.sitepointstatic.com/images/tech/607-jquery-mobile-screen.png" alt="jQuery mobile interface" class="right" /></p><p>In essence, jQuery mobile helps you build cross-platform mobile web applications using HTML5. Common elements such as pages, toolbars, dialogs, lists, navigation and form fields are styled and transformed into an attractive iPhone-inspired mobile interface.</p><p>Impressively, jQuery Mobile provides A-grade support for all modern platforms including: iOS 3.2+, Android 2.1+, Windows Phone 7+, Blackberry 6+, WebOS 1.4+, Firefox Mobile, Opera Mobile 11, Meego 1.2, Kindle 3 and Kindle Fire. Lesser browsers such as Blackberry 5, Opera Mini, and Symbian will work but features such as Ajax navigation may be disabled. Older browsers will still receive a functional, non-enhanced HTML-only experience.<div>  <script type='text/javascript'>GA_googleFillSlot("InArticle_728x90_1");</script> </div></p><p>A-grade support also extends to the desktop editions of IE (7+), Chrome, Firefox and Opera. That should make testing significantly easier for developers.</p><h2>How to use jQuery Mobile</h2><p>The jQuery documentation is impressive:</p><ul><li><a
href="http://jquerymobile.com/demos/1.0/docs/about/getting-started.html">Quick Start Guide</a></li><li><a
href="http://jquerymobile.com/demos/1.0/">Documentation and Demonstrations</a></li><li><a
href="http://www.jqmgallery.com/">jQuery Mobile Gallery</a></li></ul><p>Those with a little HTML experience can implement basic multi-page templates and transitions using markup alone:</p><pre><code>
&lt;!DOCTYPE html&gt;
&lt;html&gt;
	&lt;head&gt;
	&lt;title&gt;My Page&lt;/title&gt;
	&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
	&lt;link rel=&quot;stylesheet&quot; href=&quot;http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css&quot; /&gt;
	&lt;script type=&quot;text/javascript&quot; src=&quot;http://code.jquery.com/jquery-1.6.4.min.js&quot;&gt;&lt;/script&gt;
	&lt;script type=&quot;text/javascript&quot; src=&quot;http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;one&quot; data-role=&quot;page&quot;&gt;
	&lt;div data-role=&quot;header&quot;&gt;
		&lt;h1&gt;Page One&lt;/h1&gt;
	&lt;/div&gt;
	&lt;div data-role=&quot;content&quot;&gt;
		&lt;p&gt;Hello world&lt;/p&gt;
		&lt;p&gt;&lt;a href=&quot;#two&quot; data-role=&quot;button&quot;data-transition=&quot;slide&quot;&gt;Show page 2&lt;/a&gt;&lt;/p&gt;
	&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;two&quot; data-role=&quot;page&quot;&gt;
	&lt;div data-role=&quot;header&quot;&gt;
		&lt;h1&gt;Page Two&lt;/h1&gt;
	&lt;/div&gt;
	&lt;div data-role=&quot;content&quot;&gt;
		&lt;p&gt;Hello again&lt;/p&gt;
		&lt;p&gt;&lt;a href=&quot;#one&quot; data-role=&quot;button&quot;&gt;Show page 1&lt;/a&gt;&lt;/p&gt;
	&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre><p>Those requiring more sophistication can <a
href="http://jquerymobile.com/demos/1.0/docs/api/">access the API</a> to configure the defaults, define events and modify themes.</p><h2>Building Your Own Theme</h2><p>If you&#8217;re not keen on the subtle blue and gray iPhone design, the theme can be tweaked using CSS. If that&#8217;s a little too much effort, try the <a
href="http://jquerymobile.com/themeroller/">ThemeRoller application</a>. The whole design can be modified by dragging colors on to interface elements and downloading the customized CSS file.</p><h2>Suitable File Sizes?</h2><p>jQuery Mobile&#8217;s JavaScript code is contained in a <a
href="http://jquerymobile.com/download/">24KB minified and gzipped file</a>. A further 7KB is required for the CSS theme and 32KB for the jQuery 1.6.4 core. That&#8217;s a total of 63KB &#8212; a reasonable download for the slowest of connections. Don&#8217;t forget that you&#8217;ll probably require fewer graphics too.</p><p><a
href="http://jquerymobile.com/">jQuery Mobile</a> looks great. It won&#8217;t magically convert your existing project to a mobile app but it&#8217;ll make the task far easier, more reliable and it&#8217;ll work on multiple devices.</p><p>Are you intending to use jQuery Mobile in your next project?</p><div
style="text-align:center;padding-bottom:50px;"><div
style="float:left;padding-left:30px;"> <script>GA_googleFillSlot("Edit_300x100_C");</script> </div><div
style="float:right;padding-right:30px;"> <script>GA_googleFillSlot("Edit_300x100_D");</script> </div></div><div
style="clear:both"></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/jquery-mobile-1-released/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Developing a Better Country Selector</title><link>http://www.sitepoint.com/better-country-selector/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=better-country-selector</link> <comments>http://www.sitepoint.com/better-country-selector/#comments</comments> <pubDate>Mon, 14 Nov 2011 18:30:39 +0000</pubDate> <dc:creator>Craig Buckler</dc:creator> <category><![CDATA[Best Practices]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[JavaScript & Ajax Tutorials]]></category> <category><![CDATA[JavaScript & CSS]]></category> <category><![CDATA[jQuery]]></category> <category><![CDATA[Usability]]></category> <category><![CDATA[country]]></category> <category><![CDATA[html]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[jquery plugins]]></category> <category><![CDATA[jQuery Tutorials & Articles]]></category> <category><![CDATA[select]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=47870</guid> <description><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2011/11/604-better-country-selector-50x50.png" class="attachment-thumbnail wp-post-image" alt="604-better-country-selector" title="604-better-country-selector" />Country lists in drop-down HTML select boxes are usually a usability nightmare. Craig reveals a new solution to help your users.]]></description> <content:encoded><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2011/11/604-better-country-selector-50x50.png" class="attachment-thumbnail wp-post-image" alt="604-better-country-selector" title="604-better-country-selector" /><p></p><p>There reaches a point in every web developer&#8217;s life when they need a country selector &#8212; perhaps for a sign-up form or delivery address. So we find a list of all 249 countries, insert a <code>select</code> box into our HTML code and consider that a job well done.</p><p>It&#8217;s not.</p><p>Country select boxes are dreadful. The problems include:</p><p><strong>1. Too many choices</strong><br
/> Locating your country within 249 items is a usability nightmare.</p><p><strong>2. An awkward interface</strong><br
/> Select box controls differ between devices, OSs and browsers but one thing is certain &#8212; the user will need to scroll around to find their country. That often means switching from keyboard to mouse or lots of swiping on your mobile.</p><p><strong>3. Sorting problems</strong><br
/> If your site is primarily visited by US users, an alphabetic list displays &#8220;United Arab Emirates&#8221; and &#8220;United Kingdom&#8221; first. Some developers address this by putting the most likely countries at the top but this can confuse users expecting an alphabetically-ordered list.</p><p><strong>4. No consideration for alternative country names</strong><br
/> Country lists rarely consider alternative names. I live in the UK but any of United Kingdom, UK, Great Britain, GB, Britain or England could be defined by the developer.<div>  <script type='text/javascript'>GA_googleFillSlot("InArticle_728x90_1");</script> </div></p><p><strong>5. Poor internalization</strong><br
/> What if a Spanish user tries to locate &#8220;Espa&ntilde;a&#8221; in your English list? At best, they&#8217;ll find Estonia. In addition, lists rarely consider international country codes such as ES or US.</p><p><strong>6. No consideration for abbreviations or mis-keying</strong><br
/> If a user enters a term such as &#8220;nited&#8221;, &#8220;States&#8221; or &#8220;America&#8221; it&#8217;s unlikely they&#8217;ll locate the USA.</p><p>Fortunately, Christian Holst from the <a
href="http://baymard.com/blog">Baymard Institute</a> has developed a solution which solves the issues for us: see <a
href="http://baymard.com/labs/country-selector"><strong>Redesigning the Country Selector</strong></a>.</p><p><img
src="http://blogs.sitepointstatic.com/images/tech/604-better-country-selector-demo.png" width="578" height="172" alt="better country selector" class="center" /></p><p>It&#8217;s a jQuery plugin which replaces a standard HTML <code>select</code> box with an auto-complete control. The jQuery UI Autocomplete plugin is supplied but you can use your own implementation if necessary.</p><p>Several properties can be defined in the HTML:</p><pre><code>
&lt;select name=&quot;Country&quot; id=&quot;country-selector&quot; autofocus=&quot;autofocus&quot;&gt;
&lt;option value=&quot;Austria&quot; data-alternative-spellings=&quot;AT &Ouml;sterreich Osterreich Oesterreich &quot;&gt;Austria&lt;/option&gt;
&lt;option value=&quot;Spain&quot; data-alternative-spellings=&quot;ES Espa&ntilde;a&quot;&gt;Spain&lt;/option&gt;
&lt;option value=&quot;United Arab Emirates&quot; data-alternative-spellings=&quot;AE UAE Emirates&quot;&gt;United Arab Emirates&lt;/option&gt;
&lt;option value=&quot;United Kingdom&quot; data-priority=&quot;2&quot; data-alternative-spellings=&quot;GB Great Britain England UK Wales Scotland&quot;&gt;United Kingdom&lt;/option&gt;
&lt;option value=&quot;United States&quot; data-priority=&quot;1&quot; data-alternative-spellings=&quot;US USA United States of America&quot;&gt;United States&lt;/option&gt;
&lt;/select&gt;
</code></pre><p>This snippet is identical to most country <code>select</code> code except:</p><ul><li>If a <code>data-priority</code> code is defined, it&#8217;s assumed to have a higher priority than countries without a code. The lower the priority number, the higher it will appear in the auto-complete list.</li><li>A space-separated list of alternative codes and spellings can be defined in the <code>data-alternative-spellings</code> attribute.</li></ul><p>To convert the <code>select</code> to an auto-complete box you simply need to call the jQuery plugin method:</p><pre><code>
$("#country-selector").selectToAutocomplete();
</code></pre><p>There are many more options so I suggest you try the demonstration and view the documentation at <a
href="http://baymard.com/labs/country-selector"><strong>baymard.com/labs/country-selector</strong></a>. The open-source code is released under the MIT License and is available at <a
href="https://github.com/JamieAppleseed/selectToAutocomplete">GitHub</a>.</p><p>The plugin is far superior to other implementations I&#8217;ve seen &#8212; including, ahem, my own. Note that it doesn&#8217;t work in IE6 or 7 but those browsers will still display the standard <code>select</code> box. It&#8217;s not limited to countries either and you can use any type of data. Recommended.</p><div
style="text-align:center;padding-bottom:50px;"><div
style="float:left;padding-left:30px;"> <script>GA_googleFillSlot("Edit_300x100_C");</script> </div><div
style="float:right;padding-right:30px;"> <script>GA_googleFillSlot("Edit_300x100_D");</script> </div></div><div
style="clear:both"></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/better-country-selector/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>How to Create Multiple Borders in CSS3</title><link>http://www.sitepoint.com/css3-multiple-borders/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=css3-multiple-borders</link> <comments>http://www.sitepoint.com/css3-multiple-borders/#comments</comments> <pubDate>Fri, 11 Nov 2011 17:28:27 +0000</pubDate> <dc:creator>Craig Buckler</dc:creator> <category><![CDATA[CSS Tutorials]]></category> <category><![CDATA[HTML & CSS]]></category> <category><![CDATA[JavaScript & CSS]]></category> <category><![CDATA[Layout]]></category> <category><![CDATA[border]]></category> <category><![CDATA[CSS]]></category> <category><![CDATA[CSS3]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=47850</guid> <description><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2011/11/603-css3-multiple-borders-50x50.png" class="attachment-thumbnail wp-post-image" alt="603-css3-multiple-borders" title="603-css3-multiple-borders" />Craig's quick tutorial illustrates how you can create multiple borders in CSS3 without using images.]]></description> <content:encoded><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2011/11/603-css3-multiple-borders-50x50.png" class="attachment-thumbnail wp-post-image" alt="603-css3-multiple-borders" title="603-css3-multiple-borders" /><p></p><p>The CSS2.1 <code>border</code> property has served us well but it&#8217;s a little basic. What if you require two or more borders in different colors? The <a
href="http://www.w3.org/TR/css3-background/#border-images">CSS3 border-image property</a> is an option but it still requires Photoshopping shenanigans and the syntax is quite complex. However, if you simply need a series of solid-color borders, there is an easier alternative: the <code>box-shadow</code> property.</p><p><img
src="http://blogs.sitepointstatic.com/images/tech/603-css3-multiple-borders-box.png" width="340" height="204" alt="CSS3 Multiple Borders" class="center" /></p><p><a
href="http://blogs.sitepointstatic.com/examples/tech/css3-multiple-borders/index.html"><strong>View the multiple border demonstration page&hellip;</strong></a></p><p>box-shadow has six arguments:</p><ol><li><strong>inset</strong>: <em>(optional)</em> if defined, the shadow will appear inside the element.</li><li><strong>horizontal</strong>: the x distance from the element</li><li><strong>vertical</strong>: the y distance from the element</li><li><strong>blur</strong>: <em>(optional)</em> the blur radius, i.e. 0 for no blur</li><li><strong>spread</strong>: <em>(optional)</em> the distance the shadow spreads, i.e. 1px extends the shadow 1 pixel in all directions so it&#8217;s 2px wider and taller than the parent element</li><li><strong>color</strong>: the shadow color</li></ol><p>The little-used <code>spread</code> argument can be used to create a border. For example, a 1 pixel solid black border can be created using no blur and a 1px spread:<div>  <script type='text/javascript'>GA_googleFillSlot("InArticle_728x90_1");</script> </div></p><p><a
href="http://bc02cgw9-9vefrfvuzpcu9wy58.hop.clickbank.net/"><img
src="http://archon.autotrafficbuddy.s3.amazonaws.com/banners/250x250.gif"/></a></p><pre><code>
box-shadow: 0 0 0 1px #000;
</code></pre><p>Unlike the <code>border</code> property, <code>box-shadow</code> permits multiple shadows separated with a comma. The last shadow defined sits at the bottom of the stack so, to create the box shown above, we use this code:</p><pre><code>
box-shadow:
	0 0 0 2px #000,
	0 0 0 3px #999,
	0 0 0 9px #fa0,
	0 0 0 10px #666,
	0 0 0 16px #fd0,
	0 0 0 18px #000;
</code></pre><p>Note:</p><ul><li>The effect works in all the latest browsers including IE9.</li><li>It can be combined with <code>border-radius</code> but remember that the radius is applied to the inner element so the outer shadows extrude accordingly.</li><li>Unlike a real border, <code>box-shadow</code> does not require space so the effect will flow under other elements.</li></ul><p>Some will consider it a hack, but it&#8217;s an quick solution for multiple borders which doesn&#8217;t require images.</p><div
style="text-align:center;padding-bottom:50px;"><div
style="float:left;padding-left:30px;"> <script>GA_googleFillSlot("Edit_300x100_C");</script> </div><div
style="float:right;padding-right:30px;"> <script>GA_googleFillSlot("Edit_300x100_D");</script> </div></div><div
style="clear:both"></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/css3-multiple-borders/feed/</wfw:commentRss> <slash:comments>15</slash:comments> </item> <item><title>What&#8217;s New in jQuery 1.7</title><link>http://www.sitepoint.com/jquery-17-whats-new/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=jquery-17-whats-new</link> <comments>http://www.sitepoint.com/jquery-17-whats-new/#comments</comments> <pubDate>Sat, 05 Nov 2011 11:15:34 +0000</pubDate> <dc:creator>Craig Buckler</dc:creator> <category><![CDATA[JavaScript]]></category> <category><![CDATA[JavaScript & Ajax Tutorials]]></category> <category><![CDATA[JavaScript & CSS]]></category> <category><![CDATA[jQuery]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[jQuery Tutorials & Articles]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=47619</guid> <description><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2010/10/435-jquery-143.jpg" class="attachment-thumbnail wp-post-image" alt="435-jquery-143" title="435-jquery-143" />Craig looks at what's new, improved and removed in the latest release of the web's most popular JavaScript library.]]></description> <content:encoded><![CDATA[<img
width="50" height="50" src="http://cdn.sitepoint.com/wp-content/uploads/2010/10/435-jquery-143.jpg" class="attachment-thumbnail wp-post-image" alt="435-jquery-143" title="435-jquery-143" /><p></p><p>The web&#8217;s most popular JavaScript library has been updated. jQuery 1.7 can now be downloaded from <a
href="http://docs.jquery.com/Downloading_jQuery">docs.jquery.com/Downloading_jQuery</a>. Alternatively, if you prefer a CDN, use any of the following URLs:</p><ul><li><a
href="http://code.jquery.com/jquery-1.7.min.js">http://code.jquery.com/jquery-1.7.min.js</a></li><li><a
href="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js">http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js</a></li><li><a
href="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.min.js">http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.min.js</a></li></ul><p>So let&#8217;s look at what&#8217;s new&hellip;</p><h2>Removed Features</h2><p>Before we look at the new and shiny stuff, you should check your existing code. Are you using:</p><ul><li>event.layerX or event.layerY</li><li>jQuery.isNaN() <em>(undocumented utility function)</em></li><li>jQuery.event.proxy() <em>(undocumented method)</em></li></ul><p>If you are, jQuery 1.7 may break your system.</p><h2>New Event APIs: on() and off()</h2><p>The new on() and off() methods unify event handling in jQuery so there&#8217;s no need to use bind(), delegate() or the older live() calls. The syntax:<div>  <script type='text/javascript'>GA_googleFillSlot("InArticle_728x90_1");</script> </div></p><pre><code>
$(elements).on( events [, selector] [, data] , handler );
$(elements).off( [events] [, selector] [, handler] );
</code></pre><p>Example 1 &#8212; bind a click event to a link:</p><pre><code>
// onclick
$("a#mylink").on( "click", MyHandler );
// identical
// to: $("a#mylink").bind( "click", MyHandler );
// or: $("a#mylink").click( MyHandler );
</code></pre><p>Example 2 &#8212; bind a click event to all items in an unordered list using a delegate:</p><pre><code>
// onclick
$("ul#mylist").on( "click", "li", MyHandler );
// identical to:
// $("ul#mylist").delegate( "li", "click", MyHandler );
</code></pre><p>The existing bind() and delegate() methods still exist, but the team recommend you use on() and off() for all new projects using jQuery 1.7.</p><h2>HTML5 Support for IE6, 7 and 8</h2><p>Methods such as html() now support HTML5 tags such as <code>header</code>, <code>footer</code> and <code>article</code>. Note that you&#8217;ll still require the <a
href="http://code.google.com/p/html5shiv/">HTML5 shiv</a> in those browsers.</p><h2>New isNumeric() method</h2><p>As you probably guessed, the new <a
href="http://api.jquery.com/jQuery.isNumeric/">isNumeric()</a> function returns true if a value is a number, e.g.</p><pre><code>
$.isNumeric(10);		// true
$.isNumeric("10");		// true
$.isNumeric(0);			// true
$.isNumeric("");		// false
$.isNumeric(true);		// false
$.isNumeric(Infinity);	// false
</code></pre><h2>New Callbacks() object</h2><p>The <a
href="http://api.jquery.com/category/callbacks-object/">jQuery.Callbacks()</a> object returns a multi-purpose object used to manage callback lists. In essence, it&#8217;s a generalized way to queue and trigger a series of handlers. It&#8217;s an advanced feature &#8212; in most situations, the higher-level <a
href="http://api.jquery.com/category/deferred-object/">jQuery.Deferred object</a> will be preferable.</p><h2>Miscellaneous Improvements and Bug Fixes</h2><p>The following issues have been addressed:</p><ul><li>Delegate event performance has doubled in 1.7. The jQuery team identified that delegation had become increasingly important in application frameworks and made further optimizations to the core code.</li><li>Toggling animations including slideToggle() and fadeToggle() now work correctly following a termination of queued effects using stop().</li><li>The <a
href="http://api.jquery.com/is/">is() method</a> now correctly filters positional selectors such as :first, :last and :even against the document &#8212; not the jQuery object passed to <code>is()</code>.</li><li>The <a
href="http://api.jquery.com/removeData/">.removeData() method</a> now accepts one or more keys within an array or a space-separated string.</li><li>The <a
href="http://api.jquery.com/stop/">.stop() method</a> can be passed an optional string representing the name of the animation queue.</li><li>jQuery now supports the <a
href="https://github.com/amdjs/amdjs-api/wiki/AMD">Asynchronous Module Definition (AMD)</a> for defining modules and dependencies.</li></ul><h2>Documentation Updates</h2><p>For further details of all the new features, refer to the <a
href="http://api.jquery.com/category/version/1.7/">1.7 documentation page</a>. All new features are tagged with <em>&#8220;New in 1.7&#8243;</em>.</p><h2>Should You Upgrade?</h2><p>That&#8217;s the million dollar question. The jQuery team work hard to minimize compatibility issues and version 1.7 is unlikely to break your code. That said, if you&#8217;re particularly risk-averse, delay updating for a week or two. Minor bugs are normally found, fixed and released quickly.</p><div
style="text-align:center;padding-bottom:50px;"><div
style="float:left;padding-left:30px;"> <script>GA_googleFillSlot("Edit_300x100_C");</script> </div><div
style="float:right;padding-right:30px;"> <script>GA_googleFillSlot("Edit_300x100_D");</script> </div></div><div
style="clear:both"></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/jquery-17-whats-new/feed/</wfw:commentRss> <slash:comments>13</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 46/140 queries in 0.208 seconds using memcached
Object Caching 3053/3279 objects using memcached
Content Delivery Network via cdn.sitepoint.com

Served from: www.sitepoint.com @ 2012-02-09 20:41:25 -->
