基于Jquery的溫度計動畫效果
更新時間:2010年06月18日 23:57:10 作者:
將代碼一一拷貝到頁面相應(yīng)的位置,然后記得調(diào)用jquery框架,展示條件有限,所以效果跟設(shè)計圖有出入,但實現(xiàn)原理是一樣的,歡迎大家多多交流!
設(shè)計圖如下:

1.xhml
<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="請輸入0-100的數(shù)值" id="num"/>
<input name="" type="button" id="Risk" value="查看度數(shù)" />
2.css
#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
$(document).ready(function(){
$("#hot").fadeTo(0,0);//初始透明度為0;
$('#num').click(function(){this.select();})
$('#Risk').click(function(){
inputvalue=$('#num').val();//val()獲取input元素的值,另外還可以用attr("value")來獲??;
var inputnum=parseInt(inputvalue);
if($('#num').val().search("^-?\\d+$") != 0){
alert("請輸入一個0-100的整數(shù)!");
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('slow',Columnhe);
//在這里把html換成text效果也是一樣的;
});
});
將代碼一一拷貝到頁面相應(yīng)的位置,然后記得調(diào)用jquery框架,展示條件有限,所以效果跟設(shè)計圖有出入,但實現(xiàn)原理是一樣的,歡迎大家多多交流!

1.xhml
復(fù)制代碼 代碼如下:
<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="請輸入0-100的數(shù)值" id="num"/>
<input name="" type="button" id="Risk" value="查看度數(shù)" />
2.css
復(fù)制代碼 代碼如下:
#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
復(fù)制代碼 代碼如下:
$(document).ready(function(){
$("#hot").fadeTo(0,0);//初始透明度為0;
$('#num').click(function(){this.select();})
$('#Risk').click(function(){
inputvalue=$('#num').val();//val()獲取input元素的值,另外還可以用attr("value")來獲??;
var inputnum=parseInt(inputvalue);
if($('#num').val().search("^-?\\d+$") != 0){
alert("請輸入一個0-100的整數(shù)!");
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('slow',Columnhe);
//在這里把html換成text效果也是一樣的;
});
});
將代碼一一拷貝到頁面相應(yīng)的位置,然后記得調(diào)用jquery框架,展示條件有限,所以效果跟設(shè)計圖有出入,但實現(xiàn)原理是一樣的,歡迎大家多多交流!
您可能感興趣的文章:
相關(guān)文章
jQuery動態(tài)設(shè)置form表單的enctype值(實現(xiàn)代碼)
本篇文章是對在jQuery中動態(tài)設(shè)置form表單的enctype值的實現(xiàn)代碼進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-07-07Jquery中LigerUi的彈出編輯框(實現(xiàn)方法)
本篇文章是對Jquery中LigerUi的彈出編輯框的實現(xiàn)方法進(jìn)行了分析介紹,需要的朋友可以參考下2013-07-07Javascript技巧之不要用for in語句對數(shù)組進(jìn)行遍歷
Javascript技巧-不要用for in語句對數(shù)組進(jìn)行遍歷的一些原因分析,需要的朋友可以參考下。2010-10-10jQuery動態(tài)創(chuàng)建html元素的常用方法匯總
這篇文章主要介紹了jQuery動態(tài)創(chuàng)建html元素的常用方法,包括jQuery追加元素、遍歷數(shù)組以及使用模板等方法,非常具有實用價值,需要的朋友可以參考下2014-09-09