A few short jquery codes implement an image scroll up switch.

Source: Internet
Author: User

In a few short jquery codes, you can scroll up an image.

Description of the animate () parameter:

The animate () method executes the Custom Animation of the CSS property set.

This method uses the CSS style to change an element from one state to another. The CSS attribute value is gradually changed, so that you can create an animation effect.

Only numeric values can be used to create animations (such as "margin: 30px "). The string value cannot be used to create an animation (for example, "background-color: red ").

PS: however, if you reference the latest jquery ui framework, attributes such as backgroudColor and color can also achieve gradient.

PS: Use "+ =" or "-=" to create relative animations ).

First, you still need to reference the jquery framework.

First look at the effect:

OneTwoThree

Let's take a look at the Code:

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

The js part can also achieve a rollback effect:

$ (Document). ready (function (){
Var Top =-350;
Var Time = 500;
Var more =-50;
Function move (){
$ ("# Box"). animate ({"margin-top": Top + more}, Time );
$ ("# Box"). animate ({"margin-top": Top}, 300 );
Top + =-350;
If (Top ==- 1050)
{
Top = 0;
More = 50;
Time = 400;
}
Else
{
Time = 500;
More =-50;
}
}
SetInterval (move, 3000 );
})

Effect:

OneTwoThree

Article Source: Xiaosheng

 http://www.colorff.com

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.