网站加载,数字滚动+将数字转换成带中文的值

 

 

 

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript" src="jquery-1.11.2.min.js"></script>
</head>
<body>
<style type="text/css">
.number1{
font-family: "微软雅黑";
color: #ef7a46;
font-size: 26px;
vertical-align: super;
}
.red{
font-size: 12px;
color: #666;
vertical-align: super;
}
</style>


<div class="number1">
<input class="date" type="hidden" value="56445565465256556">
</div>
<div class="number1">
<input class="date" type="hidden" value="564455654652565564">
</div>
<div class="number1">
<input class="date" type="hidden" value="564455654652">
</div>

<script>

$(".number1").each(function(index,ele){

var numbers = $(ele).find("input").val();
var digit = numbers.indexOf("."); // 取得小数点的位置
var int = numbers.substr(0, digit); // 取得小数中的整数部分
var i;
var mag = new Array();
var word;
if (numbers.indexOf(".") == -1) { // 整数时
i = numbers.length; // 整数的个数
while (i > 0) {
word = numbers.substring(i, i - 4); // 每隔4位截取一组数字
i -= 4;
mag.unshift(word);
}
} else { // 小数时
i = int.length; // 除小数外,整数部分的个数
while (i > 0) {
word = int.substring(i, i - 4); // 每隔4位截取一组数字
i -= 4;
mag.unshift(word);
}
var usnd=numbers.substring(digit)
}

for(var i in mag){
var heid=mag[i];
if (i==mag.length-2) {
$(ele).append("<span class='timer' id='count-number' data-to='"+heid+"' data-speed='1500'></span><span class='red'>万</span>");
}else if(i==mag.length-3){
$(ele).append("<span class='timer' id='count-number' data-to='"+heid+"' data-speed='1500'></span><span class='red'>亿</span>");
}else{
$(ele).append("<span class='timer' id='count-number' data-to='"+heid+"' data-speed='1500'></span>");
}
}
$(ele).append(usnd);
})

 


</script>

<script type="text/javascript" src="countup.js">

$.fn.countTo = function(a) {
    a = a || {};
    return $(this).each(function() {
        var c = $.extend({},
        $.fn.countTo.defaults, {
            from: $(this).data("from"),
            to: $(this).data("to"),
            speed: $(this).data("speed"),
            refreshInterval: $(this).data("refresh-interval"),
            decimals: $(this).data("decimals")
        },
        a);
        var h = Math.ceil(c.speed / c.refreshInterval),
        i = (c.to - c.from) / h;
        var j = this,
        f = $(this),
        e = 0,
        g = c.from,
        d = f.data("countTo") || {};
        f.data("countTo", d);
        if (d.interval) {
            clearInterval(d.interval)
        }
        d.interval = setInterval(k, c.refreshInterval);
        b(g);
        function k() {
            g += i;
            e++;
            b(g);
            if (typeof(c.onUpdate) == "function") {
                c.onUpdate.call(j, g)
            }
            if (e >= h) {
                f.removeData("countTo");
                clearInterval(d.interval);
                g = c.to;
                if (typeof(c.onComplete) == "function") {
                    c.onComplete.call(j, g)
                }
            }
        }
        function b(m) {
            var l = c.formatter.call(j, m, c);
            f.html(l)
        }
    })
};
$.fn.countTo.defaults = {
    from: 0,
    to: 0,
    speed: 1000,
    refreshInterval: 100,
    decimals: 0,
    formatter: formatter,
    onUpdate: null,
    onComplete: null
};
function formatter(b, a) {
    return b.toFixed(0)
}
$("#count-number").data("countToOptions", {
    formatter: function(b, a) {
        return b.toFixed(0).replace(/\B(?=(?:\d{3})+(?!\d))/g, ",")
    }
});
$(".timer").each(count);
function count(a) {
    var b = $(this);
    a = $.extend({},
    a || {},
    b.data("countToOptions") || {});
    b.countTo(a)
};

 

</script>
</body>
</html>

posted @ 2017-01-20 11:12  断弦✦浪ლ小子  阅读(378)  评论(0编辑  收藏  举报