1+ <!DOCTYPE html>
2+ < html >
3+ < head lang ="en ">
4+ < meta charset ="UTF-8 ">
5+ < title > </ title >
6+ < style >
7+ body {font-size : 12px ;color : # 666 ;background : # fff ;}
8+ # box_bg {width : 440px ;height : 10px ;background : url(../ images/bg.gif) no-repeat;padding : 24px 48px ;margin : 0 auto;}
9+ # container {height : 10px ;position : relative;}
10+ .line {height : 10px ;position : absolute;}
11+ # white , # green {width : 100% ;}
12+ # green {background : url(../ images/green.gif) repeat-x # 00FF00 ;height : 10px ;}
13+ # red {background : url(../ images/red.gif) repeat-x # FF0000 ;height : 10px ;width : 50% ;}
14+ # white {background-color : yellow}
15+ # vs {width : 40px ;height : 40px ;background : url(../ images/vs.gif) no-repeat;line-height : 40px ;text-align : center;position : absolute;left : 205px ;top : -10px ;display : none}
16+ .scope {height : 24px ;text-align : center;}
17+ .scope span {color : # FF3300 ;font-weight : bold;padding : 0 5px ;}
18+ # all2 {margin : 0 auto }
19+ # aa2 {float : left}
20+ # bb2 {float : right}
21+ </ style >
22+ </ head >
23+ < body >
24+ < div id ="box_bg ">
25+ < div id ="container ">
26+ <!--绿色条层级在最下面,宽度为100%-->
27+ < div id ="green " class ="line "> </ div >
28+ <!--红色条在绿色条上面,宽度为50%-->
29+ < div id ="red " class ="line "> </ div >
30+ <!--白色条在最上边,最开始是遮住红绿色条的-->
31+ < div id ="white " class ="line "> </ div >
32+ < div id ="vs "> </ div >
33+ </ div >
34+ </ div >
35+ < div style ="width:440px; margin:0 auto; ">
36+ < div id ="aa2 " class ="scope "> 正方< span id ="aa "> </ span > 票</ div >
37+ < div id ="bb2 " class ="scope "> 反共< span id ="bb "> </ span > 票</ div >
38+ < div id ="all2 " class ="scope "> 总共< span id ="all "> </ span > 票</ div >
39+ </ div >
40+ </ body >
41+ < script src ="../js/jquery.min.js "> </ script >
42+ < script >
43+ $ ( document ) . ready ( function ( ) {
44+ var a = 500 ; //可以改为动态
45+ var b = 130 ;
46+ $ ( "#white" ) . animate ( { width : 0 , left : "220px" } , 1000 , function ( ) { //宽度变为0的同时,让位置往左边移动父级(box_bg,container)的一半,正好到中间,形成红绿条同时出现
47+ $ ( "#vs" ) . fadeIn ( "slow" , function ( ) {
48+ $ ( "#all" ) . html ( a + b ) ;
49+ $ ( "#aa" ) . html ( a ) ;
50+ $ ( "#bb" ) . html ( b ) ;
51+ var newLeft = a / ( a + b ) * 440 - 20 + "px" ; //计算红绿条的百分比,440为总长度,20为vs宽度的一半
52+ $ ( "#vs" ) . animate ( { left : newLeft } , 1000 ) ;
53+ $ ( "#red" ) . animate ( { width : newLeft } , 1000 ) ;
54+ } ) ;
55+ } ) ;
56+ } ) ;
57+ </ script >
58+ </ html >
0 commit comments