Jquery-based thermometer animation effect

Source: Internet
Author: User
Tags html to text

The design diagram is as follows:

1. xhml
CopyCode The Code is as follows: <Div id = "mometer">
<Div id = "hot"> </div>
<Span>
<Div id = "hgheader"> 0 ℃ </div>
<Div id = "Hg"> </div>
</Span>
</Div>
<Input name = "AA" type = "text" value = "enter a value ranging from 0 to" id = "num"/>
<Input name = "" type = "button" id = "risk" value = "view level"/>

2. CSS
Copy codeThe Code is as follows: # num {color: #999 ;}
# Mometer {position: relative; Height: 100px; width: 15px; Background-color: # CCC; margin: 50px ;}
SPAN {position: absolute; display: block; bottom: 0px; width: 40px ;}
# Hgheader {Height: 15px; line-Height: 15px; color: # ff0000; font-size: 14px; font-family: Arial, Helvetica, sans-serif;
Border-bottom: # f00 1px solid; left:-40px; position: relative ;}
# Hg {Height: 0px; font-size: 0px; Background-color: # c00; width: 15px ;}
# Hot {Height: 100px; width: 15px; Background-color: # ff0; position: absolute; top: 0; left: 0 ;}

3. js

Copy code The Code is as follows: $ (document). Ready (function (){
$ ("# Hot"). fadeto (0, 0); // The initial transparency is 0;
$ ('# Num'). Click (function () {This. Select ();})
$ ('# Risk'). Click (function (){
Inputvalue = $ ('# num'). Val (); // Val () obtains the value of the input element. In addition, it can be obtained using ATTR ("value;
VaR inputnum = parseint (inputvalue );
If ($ ('# num'). Val (). Search ("^ -? \ D + $ ")! = 0 ){
Alert ("enter an integer between 0 and! ");
Return false;
} Else {
$ ("# Hgheader" ).html (inputvalue + "℃ ");
If (inputnum> = 100 ){
Inputnum= 100;
$ ('# Num'). Val (100)
$ ("# Hgheader" ).html (100 + "℃ ");
} Else if (inputnum <= 0 ){
Inputnum = 0;
$ ('# Num'). Val (0)
$ ("# Hgheader" ).html (0 + "℃ ");
}
}
VaR columnhe = inputnum/100;
$ ("# Hg"). animate ({Height: inputnum}, 'show ');
$ ("# Hot"). fadeto ('low', columnhe );
// Here, the effect of changing HTML to text is the same;
});
});

Copy the code one by one to the corresponding location on the page, and then remember to call the jquery framework. The display conditions are limited, so the effect is different from the design drawing, but the implementation principle is the same. You are welcome to talk 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: 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.