Jquery first-time experience (1) -- imitation of the Home Page

Source: Internet
Author: User
A few days ago, I saw an article about yundun's home page. Article After reading the Silverlight demo, it seems that the effect is quite good. Today, I am free to write a jquery demo. I will share it with you here. Beginner, younger brother, uses basic things and has nothing to say. Go to the demo directly, Code You should be able to understand it.

In 1234, five or six non-professional JavaScript people wrote messy code, but made the results. I don't know how to optimize them. Please give me more advice. The younger brother wrote a blog for the first time and was not familiar with the editor layout. He did not know why the HTML view of the editor could not post the CSS code segment, but it was still fruitless for half an hour, in the end, we can only use style = "" in the HTML tag to replace CSS, So we barely put the demo in the blog. Depressing ...... HTML code

 <!  Doctype HTML public "-// W3C // dtd html 4.01 transitional // en" "http://www.w3.org/TR/html4/loose.dtd"  > 
< Html >
< Head >
< Title > New Document </ Title >
< Meta Name = "Generator" Content = "Editplus" >
< Meta Name = "Author" Content = "" >
< Meta Name = "Keywords" Content = "" >
< Meta Name = "Description" Content = "" >
< Link Href = "CSS/home.css" REL = "Stylesheet" Type = "Text/CSS" >
<! -- <SCRIPT src = "javascript/jquery-1.7.1.min.js"> </SCRIPT> -->
< Script SRC = "Http://code.jquery.com/jquery-1.7.1.min.js" > </ Script >
< Script SRC = "Javascript/home. js" > </ Script >
</ Head >
< Body >
< Div Class = "Contentbox" >
< Div ID = "" Class = "Box" >
I
</ Div >
< Div ID = "B" Class = "Box" >
II
</ Div >
< Div ID = "C" Class = "Box" >
3.
</ Div >
< Div ID = "D" Class = "Box" >
Thu
</ Div >
< Div ID = "E" Class = "Box" >
V.
</ Div >
< Div ID = "F" Class = "Box" >
Sat.
</ Div >
</ Div >
</ Body >
</ Html >
Home.css File Code
 . Contentbox
{
Width : 300px ;
Height : 150px ;
Background : #333 ;
}
. Box
{
Width : 100px ;
Height : 75px ;
Border : Solid 1px ;
Color : # Fff ;
Position : Absolute ;
Font-family : '' ;
}
. Box: hover
{
Cursor : Pointer
}
#
{
Background : Red ;
}
# B
{
Background : Green ;
}
# C
{
Background : Purple ;
}
# D
{
Background : Black ;
}
# E
{
Background : Blue ;
}
# F
{
Background : Gray ;
}
Home. js file code
$ (Document). Ready (Function (){
VaR Current = 0;
$ ('. Box'). Data ('state', '1 ');
$ ('. Box'). Each ( Function (){
$ ( This ). Data ('position', $ ( This ). Index ())
});
$ ('. Box'). Each ( Function (){
$ ( This ).Css ({
'Left': $ ( This ). Index () % 3*100 + 7 + 'px ',
'Top': Math. Floor ($ ( This ). Index ()/3) * 75 + 7 + 'px'
})
});
$ ('. Box'). Click ( Function (){
Current = $ ( This ). Data ('position ');
If ($ ( This ). Data ('state') = '1' | $ ( This ). Data ('state') = '3 '){
$ ( This ). Prependto ('. contentbox ');
$ ( This ). Animate ({
Width: '200px ',
Height: '150px ',
Left: '7px ',
Top: '7px'
},
(500). Data ('state', '2'). siblings (). Each ( Function (){
$ ( This ). Animate ({
Width: '100px ',
Height: '30px ',
Left: '207px ',
Top: ($ (This ). Data ('position') <current? $ ( This ). Data ('position'): $ ( This ). Data ('position')-1) * 30 + 7 + 'px'
},
500)
}). Data ('state', '3 ');

} Else If ($ ( This ). Data ('state') = '2 '){
$ ('. Box'). Each ( Function (){
$ (This ). Animate ({
'Left': $ ( This ). Data ('position') % 3*100 + 7 + 'px ',
'Top': Math. Floor ($ ( This ). Data ('position')/3) * 75 + 7 + 'px ',
'Height': '75px ',
'Width': '100px'
},
500)
}). Data ('state', '1 ');
}
})
})

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.