Click here to Skip to main content
Click here to Skip to main content

jQuery Cover Flow like iTunes

By , 10 Dec 2011
 

Introduction

This article aims to show a simple way to reproduce a iTunes-like Cover Flow for our custom DIV in HTML with support of jQuery/jQueryUI libraries.

It is fully draggable with mouse and it has an auto-repositioning system to ensure that at least a Snapshot is in middle position.

A simple usage of component, shown in this article, is displayed in this screenshot:

screenshot1.JPG - Click to enlarge image

Background

This component uses jQuery library to simplify JavaScript development. Simply use a popular "Javascript Inheritance Implementation":

jquery.class.js 

This component allows creation of Object Oriented JavaScript classes useful to develop a redistributable component with own methods and attributes.

As classes are created, it is simple to create a CoverFlow object only selecting a target div with particular features.

Using the Code

The HTML target code of this jQuery component is very simple. We must have a DIV, "coverFlow1" in this example, containing many DIVs of "snapshot" class.

<html xmlns="http://www.w3.org/1999/xhtml" slick-uniqueid="1">
    <head>
        <link rel="stylesheet" type="text/css" href="css/style.css">
        <script type="text/javascript" src="js/jquery-1.7.1.js"></script>
        <script type="text/javascript" src="js/jquery-ui-1.7.2.custom.js"></script>
        <script type="text/javascript" src="js/jquery.class.js"></script>
        <script type="text/javascript" src="js/coverflow.class.js"></script>
        <script type="text/javascript" src="js/snapshot.class.js"></script>
        <script type="text/javascript" src="js/script.js"></script>
    </head>
    <body>
        <div id="coverFlow1" class="coverFlow">
                <div class="snapshot">1</div>
                <div class="snapshot">2</div>
                <div class="snapshot">3</div>
                <div class="snapshot">4</div>
                <div class="snapshot">5</div>
                <div class="snapshot">6</div>
                <div class="snapshot">7</div>
                <div class="snapshot">8</div>
                <div class="snapshot">9</div>
                <div class="snapshot">10</div>
        </div>
    </body> 

The only bond of CSS style of "snapshot" is "position:absolute" of that DIVs because JavaScript tries to reposition and resize those divs, so we have to ensure max freedom for those elements.

The script files are necessary for this work. jQuery-1.7.1.js is a jQuery library with the help of extended library jquery-ui-1.7.2.custom.js useful for particular kind of animations.

jquery.class.js as seen before, is a library that allows us creating Object Oriented Classes and so coverflow.class.js and snapshot.class.js are our two classes.

script.js is our main script. It simply creates instances of CoverFlow class:

 $(document).ready(function(){
    
    //Unbind Image Dragging in html. Avoids drag problems on CoverFlow
    $('img').bind('dragstart', function(event) { event.preventDefault(); });
    
    var coverFlowElement = $('#coverFlow1');
    var coverFlow = new CoverFlow(coverFlowElement);
        
}); 

We can see how this script with one row of code "var coverFlow = new CoverFlow(coverFlowElement);" auto-creates all necessary code for our CoverFlow component.

For developers, see downloadable codes of our two classes. The code is self explained. It simply creates methods to resize and reposition Snapshots divs in CoverFlow container.

It binds mouse dragging on CoverFlow, with auto center of nearest DIV like commons CoverFlow components in commerce.

Points of Interest

You can simply use this code for your work without JavaScript modifications. With simple CSS restyle and HTML elements in Snapshot DIVs, you can obtain this:

screenshot2.JPG - Click to enlarge image

If you want to simply modify some JavaScript code to change the appearance of this component, you can see the main CoverFlow parameters, in coverflow.class.js:

 /* Parameters */
this._snapshotClass = ".snapshot";
this._snapshotDistance = this._width / 7;
this._smoothness = 1;
this._timeAnimation = 300; 

_snapshotClass is the className of contained DIVs in CoverFlow container. _snapshotDistance is the initial distance between snapshots. _smoothness is a coefficient indicating morphing of defilated DIVs around main snapshot. _timeAnimation is milliseconds of scrolling animation of coverFlow.

Compatibility

This component was tested with following browsers:

  1. Chrome 16.0.912.63
  2. Firefox 8
  3. Internet Explorer 9

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0

About the Author

b4rc0ll0
Software Developer (Senior) n
Italy Italy
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionNot Working in iOS PhoneGap app [modified]memberMember 457657514 Apr '13 - 23:41 
I have add all these files and convert the index.html file into HTML5 and then I have checked into the device and found not working in iOS device. Please let me know where is the problem? I think dragging is not working because of "bindsMouseEvents".

modified 15 Apr '13 - 5:57.

QuestionAuto Scroll and MouseovermemberMember 997776210 Apr '13 - 3:37 
Hi Is there a way to make it Auto Scroll and also make it scroll on mouseover instead of dragging?
 
Thanks Smile | :)
QuestionNot working?memberMember 945456924 Sep '12 - 5:36 
I couldn't get this to work either...
 
Latest version of Firefox and Chrome didn't show any animation??
 
I'll start looking through the server logs - but the examples shown appear to be
just images?
 
Regards
 
Chris Parsons
AnswerRe: Not working?groupb4rc0ll03 Oct '12 - 23:00 
Can you send me a link of your work?
GeneralRe: Not working?memberMember 94545694 Oct '12 - 1:23 
It is installed on my local Apache server (not visible externally) but all I did was to unzip your source example into the 'htdocs' directory in Apache?
 
I have checked and all the style sheets and javascript links are accessible?
 
The web page I downloaded the source from did not show any animations either?
 
Regards
 
Chris Parsons
Questioncongratulations!!memberjosbram20 Jul '12 - 3:25 
Muy buen trabajo, I like it!
GeneralNicely done!memberMember 91926906 Jul '12 - 6:53 
I found this to be a very useful solution for a coverflow implementation. I do have a suggestion, though -- since you're already using jquery UI, why not also use it for mouse event control? This way, it would be a simple matter to add touch support via the great jquery UI Touch Punch solution:
http://touchpunch.furf.com/[^]
 
...for those looking for something that could (optionally) work on mobile devices as well.
 
Thanks for your great work!
GeneralMy vote of 1memberDebojyoti Saha15 Jun '12 - 8:22 
animation not work. Only Div 6 active.
GeneralRe: My vote of 1groupb4rc0ll016 Jun '12 - 13:56 
I need more informations.. which browser are u using?
GeneralRe: My vote of 1memberMember 457657516 Apr '13 - 18:49 
Hi Debojyoti,
Yes its true, I have checked and its not working. Do you find the solution for mobile device? Please let me know.
 
Thank

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 10 Dec 2011
Article Copyright 2011 by b4rc0ll0
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid