The animate function of jquery to realize the animation effect of graphics and text switching

Source: Internet
Author: User
Tags numeric value

Animate () as a method in jquery that can be used to create animation effects, the Animate () method in jquery makes the page more visually effective

In some pictures on the site we can see in the display of pictures, with the mouse gently slide on the picture can see the text of the picture information, in fact, using jquery animate function can achieve such an animation process.


1 2 3 4 5 6 7 8 <div class= "wrap" > "<div class=" cover ">

We use a div.wrap to place a picture, and a div.cover,cover that needs to be covered, to support any standard HTML content. Then copy the above code into a group of pictures.


We need to use CSS to line up the. Wrap, and to hide a part of the. Cover overlay, when the mouse is sliding up to show it by calling jquery.


1 2 3 4 5 6 7 . wrap{position:relative float:left; width:200px; height:200px; margin:5px; Background: #e8f5fe;  Overflow:hidden;} . Wrap Img{position:absolute top:0 left:0} wrap h3{line-height:30px; font-size:14px; color: #fff}. Wrap P{line-height:  20px}. Cover{position:absolute background: #000; height:120px; width:100%; padding:3px; top:170px; }

It is noteworthy that the hidden. Cover part uses the Position:absolute absolute positioning, which overwrites the layer. Cover only displays the title section, just set the top:170px, Because of this. The height of the wrap is 200px, and the height of the caption H3 is 30px, which is subtracted.


First I set the opacity of the overlay to 0.8, and then when the mouse slides over the picture, use the hover function to invoke the animate animation.


1 2 3 4 5 6 7 8 $ (function () {$ (". Cover"). CSS ("opacity",. 8);    $ (". Wrap"). Hover (function () {$ (". Cover", this). Stop (). Animate ({top: 80px "},{queue:false,duration:160});    },function () {$ (". Cover", this). Stop (). Animate ({top: "170px"},{queue:false,duration:160});  }); });

The animate function is a function of jquery to create a custom animation. The key to this function is to specify the animation form and the result style Property object. Each property in this object represents a style attribute that can be changed (such as "height", "top", or "opacity"). The animation ends when the value of each property indicates how much of the style property is. If it is a numeric value, the Style property is graduated from the current value to the specified value. If you are using a string value such as hide, show, or toggle, the default animation form is invoked for the property.

The above mentioned is the entire content of this article, I hope you can enjoy,

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.