一个简单的js投票柱状百分比特效

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <style>
    *{ margin:0; padding:0;}
    #div1{ background:#000; width:500px; height:30px; position:relative;}
    .a_1, .a_2{ position:absolute; top:0; height:30px;}
    .a_1{ left:0; background:#0F6;}
    .a_2{ right:0; background:#39C;}
    input{ margin-top:30px;}
    </style>
    <script>
    window.οnlοad=function()
    {
            var oDiv=document.getElementById('div1');
            var aDiv=oDiv.getElementsByTagName('div');
            var aBtn=document.getElementsByTagName('input');
            var lNum=50;  
            var rNum=25;
            var lNums=(rNum/(lNum+rNum))*500;
            var rNums=500-lNums;
            aDiv[1].style.width=parseInt(lNums)+'px';
            aDiv[0].style.width=500-parseInt(lNums)+'px';
            aDiv[0].innerHTML=(lNum/(lNum+rNum)).toFixed(2);
            aDiv[1].innerHTML=(1-lNum/(lNum+rNum)).toFixed(2);
                   
            aBtn[0].οnclick=function()
            {
                    lNum=lNum+1;
                    var lNumss=parseInt(lNum/(lNum+rNum)*500);
                    aDiv[0].style.width=lNumss+'px';
                    aDiv[1].style.width=(500-lNumss)+'px';
                    aDiv[0].innerHTML=(lNum/(lNum+rNum)).toFixed(2);
                    aDiv[1].innerHTML=(1-lNum/(lNum+rNum)).toFixed(2);
            }
            aBtn[1].οnclick=function()
            {
                    rNum=rNum+1;
                    var rNumss=parseInt(rNum/(lNum+rNum)*500);
                    aDiv[0].style.width=(500-rNumss)+'px';
                    aDiv[1].style.width=rNumss+'px';
                    aDiv[0].innerHTML=(lNum/(lNum+rNum)).toFixed(2);
                    aDiv[1].innerHTML=(1-lNum/(lNum+rNum)).toFixed(2);
            }
    }
    </script>
    </head>

    <body>
    <div id="div1">
            <div class="a_1"></div>
        <div class="a_2"></div>
    </div>
    <input type="button" name="aa" value="投票1" />
    <input type="button" name="aa" value="投票2" />
    </body>
    </html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值