Posted by & filed under books, JavaScript.

Book cover of HTML5 CANVAS
  • Author: Steve Fulton, Jeff Fulton
  • publisher: O’Reilly Media
  • pages: 652

Summary

Finally one extensive book over the Canvas element. This should attract the more creative ( Javascript ) programmers. I find it hard to describe the entry level of this book, however I get the feeling that novice to medior (JavaScript) developers should get along with the book.

Review

I like the introduction of the all the canvas properties, the authors filled the book with easy to follow comprehensive examples. The examples let the reader experiment with the features of Canvas. Most of the examples have some minor cross-browser issues since the canvas element is not stable yet, but the book describes these issues open and sincere which I liked. After the reader gets acquainted with the canvas element the books start with game programming and animation mathematics. The animations and math reminds me of former actionscript book, but still I learned a lot from these chapters. Flash cannot be compared one-on-one with canvas regarding; performance, animation, collision detection and resource management.

After the game sections the book briefly touches mobile applications with phoneGap and 3d with webGL. I liked these sections but I am not sure if these sections are relevant for this book.

But still the canvas is an amazing element and this books opens up a new world in html, for example chapter 5 shows some impressive examples of how easy it is to combine video with canvas; transformations, bitmap filtering its all possible. It is exiting to see that every new browser generation will be faster and will open new possibilities.

It would be nice to see some additional information in the next edition regarding business applications, for example how to overcome sandbox issues when uploading images to canvas.

Conclusion

But overall I can recommend this book to every developer who wants to be creative with the web. This book provides a solid path for developing Canvas games/ applications with a solid performance. The books product page

Posted by & filed under JavaScript, JQuery.

Get the source at Github

For a larger project of mine i needed to find a way to rotate cavas elements on mousedrag. So here’s my attempt to create this user interface functionality.

Source and example

Watch the demo

rotate canvas demo

Seperate steps

First I divided the script into logical steps to simplify the problem.

  1. create a update function for the canvas.
  2. setup the mousehandlers to register the “drag” event
  3. create a helper function to calculate the angle between 2 coordinates

The key for this functionality is that the starting angle of the drag always differs. This causes the canvas drawing to jump to unwanted angles if the script does not compensate for this.

$( model.cnv ).mousedown(function(event){
    // calculate click angle minus the last angle
    var clickAngle = getAngle(cX + offX, cY + offY, event.clientX, event.clientY ) 
       - model.angle;
    $( model.cnv ).bind("mousemove", clickAngle, function(event){
      // calculate move angle minus the angle onclick
      model.angle =  ( getAngle( cX + offX, cY + offY, event.clientX, event.clientY  )
       - clickAngle);
      updateRectangle(model.angle);
    });
});

I have not tested the script with other shapes than rectangles and squares, but the script should work fine as long as the canvas elements have ‘bounding box’ with a width and height. Of course this example is a starting point and the interface could use some custom cursors or icons.

Posted by & filed under books, JavaScript, JQuery.

Javascript the definitive guide: book cover
  • Author: David Flanagan
  • publisher: O’Reilly Media
  • pages: 1100

Summary

Novice to advanced this book will open the web as your playground, a full course on JavaScript including the new features and API’s of HTML5. It will be hard to find any topic about JavaScript which not discussed in this book.

Review

First a short introduction about me as the reviewer of this extensive Javascript book. I have worked with JavaScript for about 6 years, the last 2 years I dived more deeply into JavaScript, the main reason for this is freedom. I was mentally unrestricted in Flash and Actionscript 3, and I needed to free my mind for javascript as well.

Before this book I have read two other O’Reilly JavaScript publications; JavaScript the good parts and Javascript Patterns. Both excellent books to get a firm grasp of : structure, development and best practices of JavaScript.

For me the timing was right to dig deeper into the “framework” of JavaScript.

It immediately became clear that a lot of research has been packed into this book. The first sections explains the core features of Javascript this should get the reader quickly programming JavaScript in a right way. It is nice to see that the code examples in this section are short and self explanatory.

I read the second part with a lot of fun, this section fully prepares developers for ECMAScript 5 and HTLM 5. I learned a lot of new stuff and browser specific details. Possible pitfalls implementing new standards are clearly described. Some of the chapters I really liked were: Handling Events (17), Scripted Media and Graphics ( 21 ) and HTML5 API’s (22).

The reference is very handy, I already have used it a lot of times. It is nice to have good reference, it’s a fast, reliable and up-to-date way to look things up once familliair with the reference layout. Most times faster than a google request. With the confidence of getting clear and concise code examples.

To conclude this review I can say that this book is a must have for every “future-eager” front-end developer. This book reminds me of my worn “Essential Actionscript 3.0” book. “Essential Javascript” a.k.a Javascript the definitive guide 6th Edition can be bought O’Reilly .

Posted by & filed under JavaScript, JQuery.

Get the source at Github
A few years ago a lot of websites used an animated flash menu for their navigation. The smarter ones were build progressive above the html list. This is a canvas implementation of the same principle.

Source and example

Watch the demo

canvas menu

Thinking about the menu I had several strategies.

  • Create a canvas for each menu item
  • Create one canvas which contains the menu items and one moving canvas for the hover animation

I chose for the latter one because i had the feeling that the performance would be better with large menu’s. Of course more creative menu’s can be be created with separate canvas elements for each menu item.

The script consist of three parts.

  • Reading out the html and building the menu and creating the animation canvas.
  • Event handling.
  • Tracking the mouse position for button clicks and hover states.

This way it is possible again to create irritating accessible menu’s 😉 . Luckily most clients nowadays avoids animating menu. But trends are known to die end come back again. I still need to find a proper way to position canvas elements and offsetting the origin for mouse calculations.

Posted by & filed under books, JavaScript, JQuery.

  • Author: Giulio Bai
  • publisher: packt publishing
  • pages: 261

Introduction

Previous month Packt Publishing send me a request by e-mail for a book review. Of course I was honoured and since the book fitted nicely in my main interest, namely webdevelopment, I read the book and wrote the review below.

First impression, a good book with a fast pace. First three global chapters, then on to the fun stuff creating plugins.

Book: Jquery Plugin development

Review

The first three chapters provide a concise but clear introduction to the jQuery API and how to create plugins. The rest of the book describes the creation of plugins in different categories. For example images, audio or form plugins. I really liked this setup, the instructions are very clear and only describe the core of the plugin’s, sometimes with a little added CSS. The advantage of this approach that it is easy for beginners to understand the inner workings of existing plugins. With this understanding it will be easy to expand the plugins to the requirements of the reader. The past years I have used and modified a lot of plugins, I wish I had a book like this from the start.

Even with the experience of a few years of jquery the book is a nice recapitulation of the inner working of the plugins used daily. This book also reminded of some forgotten plugins I wanted to check out.

Another aspect I liked is that the author starts including a custom jquery.center.js plugin to be used in the gallery plugin ( chapter 4 ) and the video plugin ( chapter 6 ) right from the start, this teaches DRY right from the start ( of course with the cost of additional HTTPRequests, but that’s another topic ).

After the first half of the book the plugins get slightly more complex. During these chapters the author familiarizes the reader with more complex jQuery subjects like: custom filters, regular expressions and regular JavaScript. It is nice to see that regular Javascript is used when possible, it is good that the author shows how elegant it is to use Javascript inside jQuery. To my opinion too many developers try to avoid regular Javascript if possible, that a shame because the real power comes with jQuery and JavaScript together.

The last chapter is fun to the the author discusses some of his favourite plugins. The showcased plugin are either very useful and easy to use or display the possible power of jQuery/ Javascript.

Overall this book is a perfect addition to a jQuery learning book. It teaches the creation of jQuery plugins as well as the structure and thoughts behind common plugins. This knowledge comes in very handy exploring the vast amount of jQuery plugins.

if you’re interested, you can buy the book at Packt publishing.

Chapters

  1. What is jQuery About?
  2. Plugins Basics
  3. Our First jQuery Plugin
  4. Media Plugins: Images Plugins
  5. Media Plugins: Audio Plugins
  6. Media Plugins: Video Plugins
  7. Form Plugins
  8. User Interface Plugins
  9. User Interface Plugins: Tooltip Plugins
  10. User Interface Plugins: Menu and Navigation Plugins
  11. Animation Plugins
  12. Utility Plugins
  13. Top jQuery Plugins