投票顯示js+css(原創)

來源:互聯網
上載者:User

最近給公司做了個投票系統,不過投票結果顯示是用flash做的HOHO

全都是動態餅圖,主圖,還有曲線圖

但是看到國外有用js寫的動態效果於是自己寫了個小例子HOHO

<html>
<script language="javascript">
/**
 * 動態設定大小
 * @param obj_id,動態顯示div的id
 * @param max,最大票數
 * @madeby ok7758521ok <ok7758521ok@126.com>
 */
function setautoSize(obj_id,max)

 
 var obj_item = document.getElementById(obj_id);
 len = obj_item.style.width.length - 2;
 cur = obj_item.style.width.substring(0,len);
 //alert(cur);
 if( cur < max)
 { 
  cur++;
  document.getElementById(obj_id+"_value").innerHTML=cur+"%";
  obj_item.style.width= cur+"px";
  window.setTimeout("setautoSize('"+obj_id+"',"+max+")",10);
  
 }
 else
 {
  alert(obj_id+"ok");
  
 }
}

//JS調用方式HOHO
window.setTimeout("setautoSize('item0',300)",10);
window.setTimeout("setautoSize('item1',100)",10);
</script>
<body>

<div id="item0_value"></div><div id="item0" style="overflow: hidden; width: 1px;height:10px;background-color:#000fff;}"></div>
<br>
<div id="item1_value"></div><div id="item1" style="overflow: hidden; width: 1px;height:10px;background-color:#10ff00;}"></div>
</body>
</html> 

相關文章

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.