Using jquery to achieve the same cool dynamic tile effect as Win8

Source: Internet
Author: User
I believe you like this interface is nothing but like its dynamic magnetic paste. Just today, I studied how to imitate this effect through jquery on the Web page, and put it up for everyone to spray. Although some very low-level technology, but also hope that the need for friends can refer to the

I personally said that I like Microsoft's next generation of products, regardless of its product maturity or not, but it brings a new product. The so-called new, refers to the user experience, Apple's success over the years so that all products are imitating its interface, including Andrew, don't know how everyone feels, anyway, I'm on these rounded rectangles produce aesthetic fatigue (apple and Android fans do not spray, here is only from the interface evaluation, in fact, as a whole, Microsoft still has a gap, the introduction of WP let me in front of a bright, immediately like the Metro style products, until today WP8 and Win8 began more and more mature.

The writing is not good, welcome everybody reader to correct the criticism, does not welcome the unprovoked gush. Great God, please take a detour.

Cut the crap and get to the point. The basic idea is to define an outer div, a fixed height (such as the 180px in this example) and set the property Overflow:hidden (hide the part beyond the border), then define an inner div inside the div and set the property position: Relative (with relative layout). Inside this inner div, we define a picture, note to set its height as the outer div height (180px in this example), and then define a div to put the text, the div height and the outer div height (such as the 180px in this example, if you give a padding, The height is correspondingly reduced to the height of the entire div that is 180px. The layout code looks like this
HTML:

Copy Code code as follows:


<div id= "Outside" >


<div id= "Inside" >


<img width= "180px" height= "180px" src= "http://xxxxxxxxx picture address"/>


<div id= "text" >


<span> through jquery to achieve the same cool dynamic win8 effect </span>


<p> Lin Yu </p>


<p> I personally like Microsoft's new generation of products ......</p>


</div>


</div>


</div>


CSS:

Copy Code code as follows:


#outside


{


height:180px;


Overflow:hidden;


}


#inside


{


position:relative;


}


#text


{


width:160px;


height:160px;


background: #0000ff;


padding:10px;


color: #fff;


}


The rest is the jquery thing. First of all understand this "dynamic magnetic paste" action: A start to display a picture, and then slide up the display text, stay for a while, and then slide down to show the picture, so loop. Let's first define a function:

Copy Code code as follows:


function Go (ID, d1, px1, Val1, D2, PX2, val2) {


$ (ID). delay (D1);


$ (ID). Animate ({bottom:px1}, Val1, function () {


$ (ID). delay (D2);


$ (ID). Animate ({bottom:px2}, val2);


    });


}


Here are 7 parameters, ID is inside the div is to slide the Div id,d1 is the inner layer div sliding up to stay after the time, PX1 is the inner layer div to slide up the relative position, the default current position is 0px,val1 is the inner layer div completion of the move up the action required time, D2 is the time to move down the Div, px2 is the relative position of the downward slide, where the original position is still 0px,val2 is the time required to complete the slide down.

We then set up a timer to perform our defined go function when the page is loaded:

Copy Code code as follows:


$ (function () {


timer1 = setinterval (function () {


Go ("#inside", 1500, "180px", 1200, 1000, "0px", 2000);


}, 3000);


});


The parameters here can be modified as needed, and we let the timer perform a go function every 3 seconds.
The source code are basically posted out, there is a need for the source file of children's shoes can be punched here to download .

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.