欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js實(shí)現(xiàn)數(shù)字遞增特效【仿支付寶我的財(cái)富】

 更新時(shí)間:2017年05月05日 12:03:54   作者:小月博客  
本篇文章主要介紹了js實(shí)現(xiàn)仿支付寶我的財(cái)富里的數(shù)字遞增特效,具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧

上周五應(yīng)著公司臨時(shí)需求,一天的時(shí)間解決掉官網(wǎng)(ps:比較簡(jiǎn)單哈哈),需求里面有一個(gè)特效就是數(shù)字遞增到指定的數(shù)值,其實(shí)JS寫(xiě)也不復(fù)雜的,但是我發(fā)現(xiàn)一個(gè)js小插件,這個(gè)插件輕巧簡(jiǎn)單,用起來(lái)也非常簡(jiǎn)單實(shí)用。在這里分享給小盆友們吧,喜歡的直接拿走。

上面就是這個(gè)插件的效果,我們來(lái)看一下怎么使用的吧

第一: HTML部分這里簡(jiǎn)單列舉一個(gè)

 <div class="counter col_fourth">
  <h2 class="timer count-title" id="count-number" data-to="300" data-speed="1500"></h2>
  <p class="count-text ">小月博客</p>
 </div>

上面我們來(lái)了解兩個(gè)關(guān)鍵的東西:

  • data-to   這個(gè)屬性控制你最終要遞增的數(shù)值是多少
  • data-speed    這個(gè)看英文的意思就很清楚了就是表示數(shù)據(jù)遞增的速度了

ps: 這里的class和id  根據(jù)大家各自的修改去調(diào)整就好了,

第二: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(2)
}
$("#count-number").data("countToOptions", {
  formatter: function(b, a) {
   return b.toFixed(2).replace(/\B(?=(?:\d{3})+(?!\d))/g, ",")
  }
});
$(".timer").each(count);
function count(a) {
  var b = $(this);
  a = $.extend({},
  a || {},
  b.data("countToOptions") || {});
  b.countTo(a)
};

以上就是代碼的全部了,css部分就不在這里顯示了,demo下載的小伙伴在下面點(diǎn)擊下載吧!

其實(shí)這個(gè)插件可擴(kuò)展性很大的,至于小伙伴喜歡什么樣子的顯示自己動(dòng)手改造吧!

demo下載請(qǐng)點(diǎn)擊

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

最新評(píng)論