Html5+jquery plugin Quicksand Achieve cool StarCraft 2 class display effect (with demo source download) _jquery

Source: Internet
Author: User

This article describes the Html5+jquery plug-in quicksand implementation of the super Cool StarCraft 2 class display effect. Share to everyone for your reference, specific as follows:

Because I am a loyal cluster of StarCraft series games, in today's jquery tutorial, we will use the HTML5 and jquery plugin quicksand to create a cool StarCraft class effect chart. I hope you like it!

Let's take a look at the effect chart:

HTML5 Code

First we use HTML5 code to create an HTML document, pour the required Quicksand class library, its jquery class library, and the HTML5 class library into the following:

 <! DOCTYPE html>  
 

In the above code, we'll insert the class picture that needs to be displayed in the container, as follows:

<li data-tag= "Terran" ></li> <li data-tag=
" Protoss unit "></li> <li
the" data-tag= unit "> </li> <li data-tag=
"Terran unit" ></li> <li data-tag=" Terran unit
"></li> <li data-tag= "Terran unit" ></li> <li data-tag=" Terran the unit "> <li data-tag= "Terran unit" ></li>

In the above code, we define the class of classes, which are Terran,protoss and Zerg units respectively.

In HTML5, we can store the data in the Database property and then take it out in jquery directly using the data method call, in which we will show all the classes through the categories defined in Data-tag.

JavaScript code

Gbin1.js

Generate category navigation for the class, as follows:

$ (document). Ready (function () {
  var items = $ (' #starcraft Li '), Itemsbytag = {};
  Items.each (function (i) {
    var elem = $ (this);
    Using jquery's HTML5 data processing method to obtain the class classification
    var tag = elem.data (' tag ');
    Elem.attr (' Data-id ', i);
    Go to the space
    tag = $.trim (tag);
    if (!) (   tag in Itemsbytag)) {
      Itemsbytag[tag] = [];
    }
Add to Category
    Itemsbytag[tag].push (elem);
  ...
  ...
});

Create the actual display of the class contents as follows:

function CreateList (text,items) {
  var ul = $ (' <ul> ', {' class ': ' Hidden '});
  Generates data $.each for the class classification
  (Items,function () {
    $ (this). Clone (). APPENDTO (UL);
  });
  Ul.appendto (' #container ');
  var a = $ (' <a> ', {
    html:text,
    href: ' # ',
    data: {List:ul}}
  ). Appendto (' #navbar ');


Generates a navigation bar click action and generates a magnification effect.

Use the Live method to add event
$ (' Li ') to dynamically generated content. Live (' click ', Function (e) {
  if ($ (' #details '))
    Details '). Hide ();
  var src = $ (this). FIND (' img '). attr (' src ');
  $ (' #details '). HTML ($ ('  ', {
    src:src,
    width: ' 150px ',
    height: ' 150px '
  });
  var details = $ (' #details ');
  var offset = $ (this). offset ();
  $ (' #details '). css ({"Left": offset.left-32, "Top": offset.top-32}). Show (function () {
    $ (' #details img '). Animate ( {
      width: ' 150px ',
      height: ' 150px ',
    }, ()
  }
;});

CSS Code

*-------------------------Simple Reset--------------------------* * *{margin:0;
padding:0; }/*-------------------------general Styles--------------------------/* html{background:url (' ...
/unit/bg_tile.jpg ') #000d20;
  body{font:14px Arial, Sans-serif;
min-height:930px;
  } A, a:visited {text-decoration:none;
  Outline:none;
Color: #54a6de; a:hover{Text-decoration:underline}/*----------------------------Headers-----------------------------*/Header
  {display:block;
  height:120px;
padding:10px;
  } #details {display:none;
  Position:absolute;
  width:150px;
  height:150px;
  Z-index:10; Background:url ('..
  /unit/dark.png ');
  border:1px solid #222;
-moz-border-radius:5px 5px 5px 5px; } h1{Background:url ('..
  /unit/logo.gif ') no-repeat left top;
  height:60px;
  MARGIN:45PX Auto;
  Overflow:hidden;
  Text-align:center;
Text-indent: -99999px; }/*----------------------------NavBar Bar-----------------------------/* #navbar {BACKground:url ("..
  /unit/light.png ");
  Display:block;
  height:39px;
  MARGIN:25PX Auto;
  margin-top:60px;
  position:relative;
  width:600px;
Text-align:center;
  #navbar a{color: #FFFFFF;
  Display:inline-block;
  height:39px;
  line-height:37px;
  Padding:0 15px;
text-shadow:1px 1px 1px #315218; #navbar a:hover{Text-decoration:none} #navbar a.active{Background:url (".
  /unit/dark.png "); box-shadow:1px 0 0 Rgba (255, 255, 255, 0.2), -1px 0 0 rgba (255, 255, 255, 0.2), 1px 0 1px rgba (0,0,0,0.2
) inset, -1px 0 1px rgba (0,0,0,0.2) inset;
  }/*----------------------------Content area-----------------------------/* #container {display:block;
  Overflow:hidden;
  width:816px;
margin:0 Auto; } #container li{Background:url ("..
  /unit/light.png ");
  Float:left;
  height:90px;
  List-style:none outside none;
  margin:6px;
  position:relative;
  width:90px;
  -moz-box-shadow:0 0 5px #000;
  -webkit-box-shadow:0 0 5px #000; Box-shadow:0 0 5px #000;
  } #container ul{Overflow:hidden; Background:url ("..
/unit/dark.png ");

 } #container ul.hidden{Display:none;}

Full instance code click here to download the site.

PS: Here again for you to recommend a few code formatting, landscaping tools, I believe that we will use in the future development process:

Online JavaScript code Landscaping, formatting tools:
Http://tools.jb51.net/code/js

JavaScript compression/formatting/encryption tool:
http://tools.jb51.net/code/jscompress

PHP code online format Landscaping tools:
Http://tools.jb51.net/code/phpformat

XML code online formatting landscaping tools:
Http://tools.jb51.net/code/xmlcodeformat

JSON code online Format/beautify/compress/edit/Convert tools:
Http://tools.jb51.net/code/jsoncodeformat

Online JSON code inspection, inspection, landscaping, formatting tools:
Http://tools.jb51.net/code/json

More interested readers of jquery-related content can view the site's topics: A summary of Ajax usage in jquery, a summary of jquery table (table) operations tips, a summary of jquery drag-and-drop effects and techniques, a summary of jquery extension techniques, jquery Common Classic Effects Summary "jquery animation and special effects usage Summary", "jquery selector usage Summary" and "jquery common Plug-ins and Usage summary"

I hope this article will help you with your jquery programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.