RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


JavaScript and jQuery: Web Apps as Highly Interactive as Desktop Apps : Page 4

Use the advanced CSS features of JavaScript and jQuery to create web applications that behave and look like desktop applications, fueled by drag-and-drop, mouse selection, panning, zooming, and more.


A Comprehensive Example

You have seen all the single-interaction elements on their own. It is now time to compose all of them together into a comprehensive example. Figure 6 and Figure 7 show a fictional dashboard for a card game: Magic, The Gathering. The browser window is completely dedicated to the interactive dashboard, where the user can rearrange cards, select and group them, zoom into their details, or observe the deck as a whole and pan from one side of the dashboard to the other. The whole setup is much more appealing when in motion, so view this YouTube video for a demonstration.

Figure 6. A Dashboard for Magic, The Gathering, with Cards Shuffled Around: Here is a fictional dashboard for a card game: Magic, The Gathering.
Figure 7. Organizing and Grouping Cards at a Different Zoom Level: Here is a fictional dashboard for a card game: Magic, The Gathering.

The required code is nothing more than a composition of the snippets you have seen so far. For an extra bit of fun, a Shuffle button randomly rearranges the cards on the dashboard with a smooth animation via the animate() method:

$('#shuffleCards').click(function() {
  // reset panning
  $('#universe').css('top', 0).
                 css('left', 0).
                 css('bottom', 0).
                 css('right', 0);

  var maxWidth = Math.round($('#container').width()*0.3) ;
  var maxHeight = Math.round($('#container').height()*0.3);

  $('.model').each(function(model) {
    var top = Math.round(
      $('#container').height() / 3 +
      Math.random()*maxHeight*2 - maxHeight);
    var left = Math.round(
      $('#container').width() / 3 +
      Math.random()*maxWidth*2 - maxWidth);

    var movement = {'top': top, 'left': left};
    $(this).animate(movement, 1000);

Much More to Explore

You have learned how to transform a static web page into an appealing interactive experience. You leveraged JavaScript and jQuery DOM manipulation functions to mimic complex interactions that are traditionally reserved for heavier client applications. Now these interactions can live in the lightweight environment of a browser window as well.

Many other features are left to explore, such as mouse gestures and keyboard events binding. A natural next step would be to evolve the demo interface into a complete desktop and layout manager backed by a model that supports real-time filtering, layout, data mutations, and interfacing with external data providers. For this purpose, I started an open-source project, Rhizosphere, for creating the ultimate JavaScript interactive experience and innovative data visualizations.

Riccardo Govoni has been working since 2003 as a J2EE developer on a variety of applications ranging from financial services to middleware in the IP television field. He currently works for Google as a software engineer. He is a Sun Certified Java Programmer (SCJP).
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date