Implement Windows8Metro style with pure Javascript _ javascript tips-js tutorial

Source: Internet
Author: User
The style of Windows8Metro is designed to implement navigation of website or system functions. This article will introduce how to use pure Javascript to implement the style of Windows8Metro. If you are interested, refer Main features of Metro Style Design

1. The Windows 8 Metro style design enables navigation of website or system functions

2. Pure Javascript implementation

3. Support all common browsers such as IE, 360, and Chrome

4. Supports special effects such as rounded corners, shadows, and Card Switching

5. Support card zoom-in, zoom-out, add, and delete Functions

6. You can customize the background color, background image, card image, and card text of a card.

7. Any switch between cards

Metro Style

Metro Algorithm

Code for card display:

The Code is as follows:


Str ='

  • ';
    Str + ='

    ';
    Str + ='

    ';
    Str + ='
  • ';


    Mobile cell JS script:

    The Code is as follows:


    Function moveItem (objid, indexList ){
    // Determine whether to move effectively.
    Var curItem = getCurItem (objid );
    Var curIndex = curItem. index;
    For (var I = 0; I Var miIndex = parseInt (indexList [I]);
    If (curIndex + 1) = miIndex & (curIndex + 1) % colSize = 0 ){
    AlertInfo ("the last column cannot be increased! ");
    Return false;
    }
    If (miIndex> = (rowSize * colSize )){
    AlertInfo ("cannot exceed three lines! ");
    Return false;
    }
    Var cellnum = getItemCellNum (miIndex );
    If (cellnum! = 1 ){
    AlertInfo ("Currently, only one cell can be moved! ");
    Return false;
    }
    }
    // Determine whether the specified display area is exceeded
    Var nullnum = 0;
    Var nullIndexArray = new Array ();
    For (var I = 0; I Var tmpItem = itemArray [I];
    Var objvalue = tmpItem. value;
    If (itemvalueforspace = objvalue | itemvaluefornull = objvalue ){
    Var isexitarea = false;
    For (var j = 0; j Var miIndex = parseInt (indexList [j]);
    If (I = miIndex ){
    Isexitarea = true;
    Break;
    }
    }
    Nullnum = nullnum + 1;
    If (! Isexitarea ){
    NullIndexArray. push (I );
    }
    }
    }
    If (itemArray. length-nullnum + indexList. length)> (rowSize * colSize )){
    AlertInfo ("the size of the cell exceeds the displayed area! ");
    Return false;
    }
    // Adjust the queue of the mobile cell.
    For (var I = 0; I Var miIndex = parseInt (indexList [I]);
    Var moveItem = itemArray [miIndex];
    If (moveItem = undefined) {// does not exist.
    For (var j = itemArray. length; j <= miIndex; j ++ ){
    AddNullItem ("");
    }
    MoveItem = itemArray [miIndex];
    }
    // Undefined
    Var moveValue = moveItem. value;
    MoveItem. value = curItem. value;
    ItemArray [miIndex] = moveItem;
    If (moveValue! = Itemvalueforspace) {// overwrite existing objects in the cell.
    // Overwrite the cell and move it to the end
    Var moveIndex = itemArray. length;
    Var col = moveIndex % colSize;
    Var row = (moveIndex-col)/colSize;
    Var moveLeft = splitspace + col * (initwidth + splitspace );
    Var moveTop = splitspace + row * (initheight + splitspace );
    Var moveCacheItem = new Object ();
    MoveCacheItem. index = moveIndex;
    MoveCacheItem. id = itemPrefix + (moveIndex + 1 );
    MoveCacheItem. x = moveLeft;
    MoveCacheItem. y = moveTop;
    MoveCacheItem. value = moveValue;
    ItemArray. push (moveCacheItem );
    Var moveObj = document. getElementById (moveValue );
    MoveObj. style. top = moveTop + "px ";
    MoveObj. style. left = moveLeft + "px ";
    } Else {// null cell. Delete the null cell.
    // Del (moveItem. id );
    }

    }

    // Check the vacant cells. If yes, the null object is filled.
    For (var I = itemArray. length-1; I >=( rowSize * colSize); I --){
    Var movitem = itemArray [I];
    Var nulitemIndex = nullIndexArray [nullIndexArray. length-1];
    Var nulitem = itemArray [nulitemIndex];
    Var moveObj = document. getElementById (movitem. value );
    // Console. log ("id =" + movitem. id + "// value =" + movitem. value + "// top =" + nulitem. y + "// left =" + nulitem. x );
    MoveObj. style. top = parseInt (nulitem. y) + "px ";
    MoveObj. style. left = parseInt (nulitem. x) + "px ";
    // Console. log ("nullid =" + nulitem. id + "// moveid =" + movitem. id + "// value =" + movitem. value + "// top =" + nulitem. y + "// left =" + nulitem. x );
    GetElement (sortablecurid). removeChild (getElement (nulitem. id ));
    Nulitem. value = movitem. value;
    ItemArray [nulitemIndex] = nulitem;
    ItemArray. pop ();
    NullIndexArray. pop ();
    }

    PrintItemArray ();
    Return true;
    }


    To be continued ......
    Related Article

    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.