search
HomeWeb Front-endJS Tutorialjs implementation of digital increment special effects example code

js implementation of digital increment special effects example code

Jul 06, 2017 am 11:34 AM
javascriptExamplespecial effects

This article mainly introduces the JS implementation of the digital increment effect in imitating Alipay My Wealth, which has a good reference value. Let’s take a look at it with the editor.

Last Friday, in response to the company’s temporary needs, we solved the official website in one day (ps: relatively simple haha). There is a special effect in the demand that is to increase the number to a specified value. , in fact, writing JS is not complicated, but I found a small js plug-in. This plug-in is light and simple, and it is also very simple and practical to use. Share it here with your little friends, take it if you like it.

The above is the effect of this plug-in, let’s take a look at how to use it

First: Here is a brief list of the HTML part

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

Let’s understand two key things above:

  • data-to This attribute Control the value you want to eventually increment

  • data-speed The meaning of this in English is very clear, it means The speed of data increment is

ps: The class and id here can be adjusted according to everyone’s own modifications,

Second: The JS part is also the core code of the plug-in

$.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)
};

The above is all the code, the css part will not be displayed here. If you want to download the demo, click to download it below!

In fact, this plug-in is very scalable. As for what kind of display your friends like, you can modify it yourself!

The above is the detailed content of js implementation of digital increment special effects example code. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Architecting Scalable JavaScript Applications with Micro-FrontendsArchitecting Scalable JavaScript Applications with Micro-FrontendsJul 21, 2025 am 03:59 AM

Micro front-end is an architectural concept that splits large front-end applications into multiple independent modules. Its core advantages include flexible technology stacks, independent deployment iteration, improving team collaboration efficiency, and supporting incremental upgrades. Common implementation methods include iframe, WebComponents encapsulation, ModuleFederation, SingleSPA framework, etc. At the same time, you need to pay attention to issues such as routing coordination, style isolation, state sharing and performance optimization.

JavaScript Module Systems: CommonJS, ES Modules, and Considerations for Java MicroservicesJavaScript Module Systems: CommonJS, ES Modules, and Considerations for Java MicroservicesJul 21, 2025 am 03:57 AM

CommonJS and ESModules are two mainstream module systems of JavaScript, suitable for different scenarios and have compatibility issues. 1. CommonJS is an early standard for Node.js. It uses require() to load modules simultaneously, which is suitable for traditional back-end services and old projects; 2. ESModules is a modern standard, which uses import asynchronous loading, supports static analysis and TreeShaking, which is suitable for new projects and modern engines; 3. The two can coexist but have limited interoperability. It is recommended to unify module types or standardize through packaging tools; 4. When integrating JS modules in Java microservices, you need to pay attention to the support of the module system and the consistency of the construction process of the operation environment.

Understanding JavaScript Prototypes and Classical Inheritance Differences with Java ClassesUnderstanding JavaScript Prototypes and Classical Inheritance Differences with Java ClassesJul 21, 2025 am 03:57 AM

Java uses a class-based inheritance model, while JavaScript relies on prototype chains to implement inheritance. In Java, a class is an object template, an instance inherits the properties and methods of the parent class, and the inheritance relationship is determined at compile time; while in JavaScript, the object directly inherits other objects, and dynamically searches properties and methods through the prototype chain, which has higher flexibility. For example, JavaScript allows the runtime to modify prototypes, affecting all relevant instances, while Java needs to be recompiled. Although ES6 introduced class syntax to make JavaScript more like Java, its underlying layer is still based on the prototype mechanism.

What are JavaScript Generators and the yield keyword?What are JavaScript Generators and the yield keyword?Jul 21, 2025 am 03:56 AM

Generator function is a special function defined using function*, which can be paused and resumed execution through yield. Returns the generator object when called, and executes each yield step by step through .next(), returning {value, done}; yield can receive input such as .next(value). Common uses include custom iterative logic, lazy evaluation (such as infinite Fibonacci sequences), and historical asynchronous process control. Note: After the generator is completed, .next() returns undefined and done:true, and can be used to end .return() in advance or .throw() throw errors. Despite the popularity of async/await, generators are in state machines and other fields

Understanding the JavaScript Event Loop Deep DiveUnderstanding the JavaScript Event Loop Deep DiveJul 21, 2025 am 03:53 AM

The execution mechanism of JavaScript is centered on event loops to solve the problem of asynchronous task scheduling. Its key structure includes call stack, heap and message queue: 1. The call stack records the functions being executed; 2. The heap stores object data; 3. The message queue stores asynchronous callbacks. The event loop distinguishes macro tasks from micro tasks, such as setTimeout, setInterval, I/O and UI rendering, and micro tasks such as Promise.then/catch/finally, queueMicrotask and MutationObserver. Each loop executes a macro task first, and then clears all micro tasks. For example, Promise.then as a micro task will be in

Exploring JavaScript Feature Policies for Browser ControlExploring JavaScript Feature Policies for Browser ControlJul 21, 2025 am 03:51 AM

FeaturePolicies(PermissionsPolicy)allowcontroloverJavaScriptbehaviorsbyselectivelyenablingordisablingbrowserfeaturesandAPIs.Tousethem,setanHTTPheaderlikePermissions-Policy:geolocation=(),fullscreen=(self)torestrictaccessbasedondomain.Youcanlimitcapab

Automated JavaScript Accessibility Testing ToolsAutomated JavaScript Accessibility Testing ToolsJul 21, 2025 am 03:50 AM

Automated JavaScript accessibility testing tools can effectively improve the efficiency of front-end barrier-free detection. 1. Tools such as axe-core, pa11y and LighthouseCLI integrated into the development process can automatically check problems in CI/CD; 2. Browser plug-ins such as axeDevTools and WAVE provide real-time debugging and intuitive feedback; 3. In unit testing, jest-axe and TestingLibrary can be combined to verify accessibility standards at the component level, helping developers establish a complete barrier-free testing process at different stages.

Advanced JavaScript WebGPU API for GraphicsAdvanced JavaScript WebGPU API for GraphicsJul 21, 2025 am 03:50 AM

WebGPU is a new generation of APIs for high-performance graphics and computing in modern browsers. It is more underlying and efficient than WebGL, and supports modern GPU functions. 1. Pipeline state object (PSO) is the core of the rendering pipeline. It should be created and reused in advance, and different pipelines should be customized according to needs to improve performance; 2. Use bindgroup and bindgrouplayout to organize resource binding, reasonably divide resource groups, avoid frequent updates of buffers, and use dynamic offsets to process instance data to improve efficiency; 3. WGSL is the default shading language of WebGPU, with strict syntax and strong type, and pay attention to memory alignment rules, making it clearer and safer after familiarity; 4. Multi-buffer management and synchronization mechanism are crucial, and multi-frame buffering is used.

See all articles

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.