当前位置:网站首页>Continuous attack animation
Continuous attack animation
2022-06-21 14:28:00 【Advanced mathematics volume II half price】
Today, let's write a fun , Continuous attack animation using higher-order functions
Pictured
Click on 10 Time , stop , The attack will continue on its own
Let's take a look at how it is implemented
html part :
<div id="main">
<button id="btn">Hit</button>
<span id="count">+0</span>
</div>css part :
#main {
padding-top: 20px;
font-size: 26px;
}
#btn {
font-size: 30px;
border-radius: 15px;
border: solid 3px #fa0;
}
#count {
position: absolute;
margin-left: 6px;
opacity: 1.0;
transform: translate(0, 10px);
}
#count.hit {
opacity: 0.1;
transform: translate(0, -20px);
transition: all .5s;
}When you click hit when ,count Set a small animation , Move up and transparency
Javascript part :
function consumer(fn, time){
let tasks = [],
timer;
return function(...args){
tasks.push(fn.bind(this, ...args));
if(timer == null){
timer = setInterval(() => {
tasks.shift().call(this)
if(tasks.length <= 0){
clearInterval(timer);
timer = null;
}
}, time)
}
}
}
btn.onclick = consumer((evt)=>{
let t = parseInt(count.innerHTML.slice(1)) + 1;
count.innerHTML = `+${t}`;
count.className = 'hit';
let r = t * 7 % 256,
g = t * 17 % 128,
b = t * 31 % 128;
count.style.color = `rgb(${r},${g},${b})`.trim();
setTimeout(()=>{
count.className = 'hide';
}, 500);
}, 800)
边栏推荐
- Simplified crud using code generation
- [graduation project recommendation] - personnel management system
- Redis learning (3) -- persistence mechanism
- Automatic operation and maintenance 3 - using playbook in ansible
- Getting started with qt-1-ui
- kernel GDB
- Oracle client11 and pl/sql12 installation
- Win10 installation and configuration mongodb
- Record the troubleshooting process of excessive CPU usage
- Automatic operation and maintenance 2 - common modules in ansible
猜你喜欢

What fun things can a desk service do

Use of MySQL 8.0.19 under alicloud lightweight application server linux-centos7

Design and implementation of object system in redis

Don't know how to interview? Test interview questions summary, teach you to face the interview questions

Qt-8- use SQL database

How can an e-commerce system automatically cancel an order when it times out?

Use Matplotlib to draw the first figure

Automatic operation and maintenance 2 - common modules in ansible

Lamp architecture 5 - MySQL Cluster and master-slave structure

Route add add route
随机推荐
Detailed explanation of dictionary source code in C #
In the autumn of 2022, from being rejected to sp+, talk about the experience and harvest of YK bacteria in 2021
Solution of difficult and miscellaneous problems in MVN packaging
Some atom operations
Redis学习(3)—— 持久化机制
Chapter 6 - application layer
Is it safe to open an account online? Can a novice open an account
Alibaba cloud log service is available in Net project
Native JS implements login function, and local cookies save login information -- [call Netease cloud API interface] - super detailed explanation
Redis learning (1) -- overview and common commands
Mr. Ali taught you how to use JMeter for pressure test (detailed drawing)
Chart. JS 2.0 doughnut tooltip percentage - chart js 2.0 doughnut tooltip percentages
Don't know how to interview? Test interview questions summary, teach you to face the interview questions
Postman testing websocket interface
module ‘selenium. webdriver‘ has no attribute ‘PhantomJS‘
Blazor webassembly integrates Ocelot gateway to solve cross domain problems
How is the redemption time of financial products stipulated?
Configuration of oracle19c under alicloud lightweight application server linux-centos7
Declare war on uncivilized code I
Define structure dynamically when macro is defined