function initdigitalincreasegiant(moduleid, layout) { if ($.inarray(layout, ['101']) > -1) { if (window.location.getquerystring('caneditfront') === 'true') { initnumber() } else { var windowtop = window.innerheight; var lock = false; // 新需求,判断第一次进入可视区域的时候执行动画 by 2018/12/27 啟锋 if ( $("#module_"+ moduleid) && $("#module_"+ moduleid).offset().top <= window.innerheight) { initnumber() } else { $(window).off('scroll.offtop'+moduleid).on('scroll.offtop'+moduleid,function() { if ($("#module_"+ moduleid)) { var moduleofftop = $("#module_"+ moduleid).offset().top var scrolltops = $(window).scrolltop() ; if( moduleofftop < ($(window).scrolltop() + windowtop) && !lock) { initnumber() lock = true } } }) } } } if ($.inarray(layout, ['103']) > -1) { createcirclechartfunction(moduleid) } } function initnumber() { $.fn.countto = function (item) { item = item || {}; return $(this).each(function () { var defaults = $.extend({}, $.fn.countto.defaults, { from: $(this).data("from"), to: $(this).data("to"), speed: $(this).data("speed"), refreshinterval: $(this).data("refresh-interval") }, item); var countdegree = math.ceil(defaults.speed / defaults.refreshinterval), score = (defaults.to - defaults.from) / countdegree; var _this = this, obj = $(this), degree = 0, itemfrom = defaults.from, countto = obj.data("countto") || {}; if (countto.interval) { clearinterval(countto.interval) } countto.interval = setinterval(calculate, defaults.refreshinterval); replacehtml(itemfrom); function calculate() { itemfrom += score; degree++; replacehtml(itemfrom); if (degree >= countdegree) { obj.removedata("countto"); clearinterval(countto.interval); itemfrom = defaults.to; } } function replacehtml(itemfrom) { var text = defaults.formatter.call(_this, itemfrom, defaults); obj.html(text) } }) }; $.fn.countto.defaults = { from: 0, to: 0, speed: 1000, refreshinterval: 100, formatter: formatter }; function formatter(num, defaults) { return num.tofixed(0).replace(/\b(?=(?:\d{3})+(?!\d))/g, ",") } $(".digital-num").each(count); function count(item) { var _this = $(this); item = $.extend({}, item || {}); _this.countto(item) }; } // 数字递增3 (function($) { "use strict"; $.fn.circlechart = function(options) { const defaults = { color: "#3459eb", backgroundcolor: "#e6e6e6", background: true, speed: 2000, widthratio: 0.11, value: 66, unit: 'percent', counterclockwise: false, size: 110, startangle: 0, animate: true, backgroundfix: true, linecap: "round", animation: "easeinoutcubic", text: false, redraw: false, cangle: 0, textcenter: true, textsize: false, textweight: 'normal', textfamily: 'sans-serif', relativetextsize: 1 / 7, autocss: true, ondraw: false }; //math functions math.lineartween = (t, b, c, d) => c * t / d + b; math.easeinquad = (t, b, c, d) => { t /= d; return c * t * t + b; }; math.easeoutquad = (t, b, c, d) => { t /= d; return -c * t * (t - 2) + b; }; math.easeinoutquad = (t, b, c, d) => { t /= d / 2; if (t < 1) return c / 2 * t * t + b; t--; return -c / 2 * (t * (t - 2) - 1) + b; }; math.easeincubic = (t, b, c, d) => { t /= d; return c * t * t * t + b; }; math.easeoutcubic = (t, b, c, d) => { t /= d; t--; return c * (t * t * t + 1) + b; }; math.easeinoutcubic = (t, b, c, d) => { t /= d / 2; if (t < 1) return c / 2 * t * t * t + b; t -= 2; return c / 2 * (t * t * t + 2) + b; }; math.easeinquart = (t, b, c, d) => { t /= d; return c * t * t * t * t + b; }; math.easeoutquart = (t, b, c, d) => { t /= d; t--; return -c * (t * t * t * t - 1) + b; }; math.easeinoutquart = (t, b, c, d) => { t /= d / 2; if (t < 1) return c / 2 * t * t * t * t + b; t -= 2; return -c / 2 * (t * t * t * t - 2) + b; }; math.easeinquint = (t, b, c, d) => { t /= d; return c * t * t * t * t * t + b; }; math.easeoutquint = (t, b, c, d) => { t /= d; t--; return c * (t * t * t * t * t + 1) + b; }; math.easeinoutquint = (t, b, c, d) => { t /= d / 2; if (t < 1) return c / 2 * t * t * t * t * t + b; t -= 2; return c / 2 * (t * t * t * t * t + 2) + b; }; math.easeinsine = (t, b, c, d) => -c * math.cos(t / d * (math.pi / 2)) + c + b; math.easeoutsine = (t, b, c, d) => c * math.sin(t / d * (math.pi / 2)) + b; math.easeinoutsine = (t, b, c, d) => -c / 2 * (math.cos(math.pi * t / d) - 1) + b; math.easeinexpo = (t, b, c, d) => c * math.pow(2, 10 * (t / d - 1)) + b; math.easeoutexpo = (t, b, c, d) => c * (-math.pow(2, -10 * t / d) + 1) + b; math.easeinoutexpo = (t, b, c, d) => { t /= d / 2; if (t < 1) return c / 2 * math.pow(2, 10 * (t - 1)) + b; t--; return c / 2 * (-math.pow(2, -10 * t) + 2) + b; }; math.easeincirc = (t, b, c, d) => { t /= d; return -c * (math.sqrt(1 - t * t) - 1) + b; }; math.easeoutcubic = (t, b, c, d) => { t /= d; t--; return c * (t * t * t + 1) + b; }; math.easeinoutcubic = (t, b, c, d) => { t /= d / 2; if (t < 1) return c / 2 * t * t * t + b; t -= 2; return c / 2 * (t * t * t + 2) + b; }; math.easeoutcirc = (t, b, c, d) => { t /= d; t--; return c * math.sqrt(1 - t * t) + b; }; math.easeinoutcirc = (t, b, c, d) => { t /= d / 2; if (t < 1) return -c / 2 * (math.sqrt(1 - t * t) - 1) + b; t -= 2; return c / 2 * (math.sqrt(1 - t * t) + 1) + b; }; let circle = (pos, bangle, eangle, cangle, radius, linewidth, sangle, settings) => { let circle = object.create(circle.prototype); circle.pos = pos; circle.bangle = bangle; circle.eangle = eangle; circle.cangle = cangle; circle.radius = radius; circle.linewidth = linewidth; circle.sangle = sangle; circle.settings = settings; return circle; }; circle.prototype = { ondraw(el) { if (this.settings.ondraw !== false) { let copy = object.assign({}, this); var units = { 'percent': rtop, 'rad': (e) => e, 'default': rtod }; copy.value = (units[this.settings.unit] || units['default'])(copy.cangle); copy.text = (text)=>setcircletext(el, text); copy.settings.ondraw(el, copy); } }, drawbackground(ctx) { ctx.beginpath(); ctx.arc(this.pos, this.pos, this.settings.backgroundfix ? this.radius * 0.9999 : this.radius, 0, 2 * math.pi); ctx.linewidth = this.settings.backgroundfix ? this.linewidth * 0.95 : this.linewidth; ctx.strokestyle = this.settings.backgroundcolor; ctx.stroke(); }, draw(ctx) { ctx.beginpath(); if (this.settings.counterclockwise) { let k = 2 * math.pi; ctx.arc(this.pos, this.pos, this.radius, k - this.bangle, k - (this.bangle + this.cangle), this.settings.counterclockwise); } else { ctx.arc(this.pos, this.pos, this.radius, this.bangle, this.bangle + this.cangle, this.settings.counterclockwise); } ctx.linewidth = this.linewidth; ctx.linecap = this.settings.linecap; ctx.strokestyle = this.settings.color; ctx.stroke(); }, animate(el, ctx, time, starttime, move/*move counterclockwise*/) { let mspf = new date().gettime() - time; //milliseconds per frame if (mspf < 1) { mspf = 1; } if ((time - starttime < this.settings.speed * 1.05)/* time not over */ && (!move && (this.cangle) * 1000 <= math.floor((this.eangle) * 1000)/* move clockwise */ || move && (this.cangle) * 1000 >= math.floor((this.eangle) * 1000)/* move counterclockwise */)) { this.cangle = math[this.settings.animation]((time - starttime) / mspf, this.sangle, this.eangle - this.sangle, this.settings.speed / mspf); ctx.clearrect(0, 0, this.settings.size, this.settings.size); if (this.settings.background) { this.drawbackground(ctx); } this.draw(ctx); this.ondraw(el); time = new date().gettime(); raf(() => this.animate(el, ctx, time, starttime, move)); } else { this.cangle = this.eangle; ctx.clearrect(0, 0, this.settings.size, this.settings.size); if (this.settings.background) { this.drawbackground(ctx); } this.draw(ctx); this.setcurrentanglesdata(el); } }, setcurrentanglesdata(el) { var units = { 'percent': rtop, 'rad': (e) => e, 'default': rtod }; let f = (units[this.settings.unit] || units['default']); el.data("current-c-angle", f(this.cangle)); el.data("current-start-angle", f(this.bangle)); } }; let setcircletext = (el, text) => { el.data("text", text); $(".circlechart_text", el).html(text); } let rtod = (rad) => rad / math.pi * 180; let dtor = (deg) => deg / 180 * math.pi; let ptor = (percent) => dtor(percent / 100 * 360); let rtop = (rad) => rtod(rad) / 360 * 100; let raf = ((c) => window.requestanimationframe || window.webkitrequestanimationframe || window.mozrequestanimationframe || window.orequestanimationframe || window.msrequestanimationframe || function(callback) { window.settimeout(c, 1000 / 60); })(); return this.each((idx, element) => { let el = $(element); var cache = {}; var _data = el.data(); for (let key in _data) { if (_data.hasownproperty(key) && key.indexof('_cache_') === 0) { if (defaults.hasownproperty(key.substring(7))) { cache[key.substring(7)] = _data[key]; } } } let settings = object.assign({}, defaults, cache, _data, options); for (let key in settings) { if(key.indexof('_cache_') !== 0) el.data('_cache_' + key, settings[key]); } if (!$("canvas.circlechart_canvas", el).length) { el.append(function() { return $('', {'class': 'circlechart_canvas'}) .prop({width: settings.size, height: settings.size}) .css(settings.autocss ? { "margin-left": "auto", "margin-right": "auto", "display": "block" } : {}); }); } if (!$("p.circlechart_text", el).length) { if (settings.text !== false) { el.append("

" + settings.text + "

"); if (settings.autocss) { if (settings.textcenter) { $("p.circlechart_text", el).css({ "position": "absolute", "line-height": (settings.size + "px"), "top": 0, "width": "100%", "margin": 0, "padding": 0, "text-align": "center", "font-size": settings.textsize !== false ? settings.textsize : settings.size * settings.relativetextsize, "font-weight": settings.textweight, "font-family": settings.textfamily }); } else { $("p.circlechart_text", el).css({ "padding-top": "5px", "text-align": "center", "font-weight": settings.textweight, "font-family": settings.textfamily, "font-size": settings.textsize !== false ? settings.textsize : settings.size * settings.relativetextsize }); } } } } if (settings.autocss) { el.css("position", "relative"); } if (!settings.redraw) { settings.cangle = settings.currentcangle ? settings.currentcangle : settings.cangle; settings.startangle = settings.currentstartangle ? settings.currentstartangle : settings.startangle; } var c = $("canvas", el).get(0); var ctx = c.getcontext("2d"); var units = { 'percent': ptor, 'rad': (e) => e, 'default': dtor }; let f = (units[settings.unit] || units['default']); let bangle = f(settings.startangle); let eangle = f(settings.value); let cangle = f(settings.cangle); var pos = settings.size / 2; var radius = pos * (1 - settings.widthratio / 2); var linewidth = radius * settings.widthratio; var circle = circle(pos, bangle, eangle, cangle, radius, linewidth, cangle, settings); el.data("size", settings.size); if (!settings.animate) { circle.cangle = circle.eangle; raf(() => { if (settings.background) { circle.drawbackground(ctx); } if (settings.value !== 0) { circle.draw(ctx); circle.ondraw(el); circle.setcurrentanglesdata(el); } else { ctx.clearrect(0, 0, this.settings.size, this.settings.size); if (circle.settings.background) { circle.drawbackground(ctx); } } }); } else { if (settings.value !== 0) { circle.animate(el, ctx, new date().gettime(), new date().gettime(), cangle > eangle); } else { raf(() => { ctx.clearrect(0, 0, this.settings.size, this.settings.size); if (circle.settings.background) { circle.drawbackground(ctx); } }); } } }); }; }(jquery));