HTML5 Canvas and CSS3 Animations

This is my last blog posting for this course, CR2170. I would like to write about animation using HTML5 canvas and CSS3 Keyframes.

What is HTML Canvas?

The HTML <canvas> element is used to draw graphics, on the fly, via scripting (usually JavaScript). The <canvas> element is only a container for graphics. You must use a script to actually draw the graphics. Canvas has several methods for drawing paths, boxes, circles, text, and adding images.

Canvas can draw colorful text, with or without animation, and it has great features for graphical data presentation with an imagery of graphs and charts. Canvas objects can move everything from simple bouncing balls to complex animations. Canvas can respond to JavaScript events and to any user action (key clicks, mouse clicks, button clicks, finger movement). Canvas’ methods for animations, offer a lot of possibilities for HTML gaming applications. (W3School.com)

What are CSS3 Animations?

An animation lets an element gradually change from one style to another. You can change as many CSS properties you want, as many times you want. To use CSS3 animation, you must first specify some keyframes for the animation. Keyframes hold what styles the element will have at certain times. (W3School.com)

My Examples

I created two animated banners for my Coffee Lounge website: the one uses HTML5 canvas animation (The Newfoundland Gardener), and the other uses CSS3 animation (Origami Competition). The Origami Competition banner is quite simple: the background and the text colors are changed by CSS Keyframes properties over a period of time. If I created the same banner with Flash animation, it would have taken much longer to set the time and the color changes the way I did in CSS animation.

Origami Gardener

Figures 1 and 2: The Origami Competition Banner and The Newfoundland Gardener Banner

Source: Naomi Kobayashi (2015)

The Newfoundland Gardener banner is more complex than the CSS animated banner. This banner has three layers (<div>s), and each layer is controlled by JavaScript functions. The letters, “The Newfoundland Gardener” and  “Subscribe Today!” move slowly from one side to the other. This banner would have been easier to create with Flash animation, since it I would not need to write a code, and stacking the <div>s in the right spot was not so easy, especially for my responsive design site.

Conclusion

HTML5 canvas and CSS Keyframes are quite different. HTML canvas is better used for more complex tasks, such as interactive animation or games, while CSS animation is more suited for providing simpler animated effects for websites. I believe HTML5 and CSS3 are good alternative for Flash animation, since they don’t require any plug-ins and work with any modern browsers. I don’t think Flash would be dead any time soon, but I believe HTML5 and CSS3 would replace some light-weight animations such as banners, since Flash animation does not work well with mobile devices. I’m not certain what would happen if we combine HTML5 canvas and CSS Keyframes together, but I would imagine creating animation would be easier and more fun using these two technologies together.

Thank you very much for reading my blog posts, and I hope you enjoy reading them. 🙂

Advertisements

Responsive Design for Better Mobile User Experience

Problems with Mobile User Experience

As I mentioned the last post, I uploaded the new version of the Coffee Lounge website in February. The site has been responsive since the last summer, but user experience for mobile phone wasn’t good, so I decided to re-design the site.

Here is the list of problems with the old version of the site had.

  1. Connection Speed
    1. Total size of CSS files was too large
    2. Total size of image files was too large
    3. Total size of all files was too large
  2. User Experience
    1. Font size was too small
    2. View point wasn’t set
    3. Tap targets were too small

I would like to hear from you about your experience of the site, so please visit the site. Your comment or suggestion for the site, especially from cell phones, is appreciated. 🙂

Mobile Site Should Design Differently From Desktop Site

Initially I designed the mobile site as a smaller, narrower version of the desktop site, but it didn’t work well. The first problem I encountered was that tables with several columns did not fit well with narrow screens.

I had three tables in the Coffee Lounge website: coffee menu, events calendar and online order form. I ended up making two separate coffee menus and events calendars because the text inside cells was not readable: even one word did not fit inside a cell without corrupting.

I changed the order form from a table to several <div>s with the display setting, table-rows in CSS styling, so it looks like a table, but it rearranges its elements on the screen as the screen width reduces.

Resolving the Problems

The site speed increased by optimizing CSS files and reducing image file size. The site had four CSS files. The two CSS files were almost identical, so I eliminated one. I replaced a large image file with several much smaller image files which are used for image buttons. The image below is the test results from Web Page Analyzer.

Download Times

Image 1: Download Times

Source: Web Page Analyzer

I followed the guidance from Google Developers for improving Mobile UX: increasing font size and line-height, setting a view point for mobile devices and enlarging the target by using a larger font for the text links and adding image buttons.

MobileUX_Before

Image 2: Mobile User Experience (Before)

Source: PageSpeed Insights

MobileUX_After

Image 3: Mobile User Experience (After)

Source: PageSpeed Insights

Results and Conclusion

The new version of the site looks much better and easier to control with smartphones. The old site was very difficult to view and to navigate from the phones with higher screen resolutions, since the site display was controlled by the number of pixels in the screen width but not the physical size of the device. Once the view point was set, the site displays as I intended for mobile devices, even if I use a smartphone.

As a conclusion, the development of responsive web design is more complicated and challenging, but it can provide reasonably good user experience for mobile phone users by optimizing CSS files, reducing image file size, using larger fonts and line-height, and providing larger tap targets.