I received a task from the company today, and the effect diagram is as follows: I didn’t specify what effect I wanted to achieve, but I thought pure digital conversion was too simple, so I just made a card flipping effect. Effect preview, open in a new window: https://codepen.io/andy-js/pen/ExaGxaL First do some page layout: <ul></ul> body{background: #000;} ul{ list-style: none; margin:100px 0; display: flex; justify-content:center; line-height: 56px; height:56px; font-size: 39.6px; color: #FFFFFF; transform-style:preserve-3d; perspective:1000px; } li{ height:56px; margin:0 10px; background:none; width:16px; position: relative; } .num{ width:46px; transform-style:preserve-3d; perspective:1000px; transform:rotateY(0deg); transition: 1s all ease; } p{ height:56px; width:46px; text-align: center; background: #EC2C5C; border-radius: 2.57px; position: absolute; } p:nth-child(2){ transform: scalex(-1) translateZ(-1px); } Then, through dynamic insertion, such an effect is simulated. Transition is used to make the animation. Transform:rotateY is used to make the flip. Before flipping, another number scalex is mirrored left and right, and then translateZ (-1px) is moved to the back of the other number. In this way, you can see the mirrored number when you flip it over. It is not perfect, and there are still many places that can be improved. The full code is as follows: <script> var number=9999993, numArr=addComma(number), aNum=[], oUl=document.getElementsByTagName('ul')[0]; for(let i=0;i<numArr.length;i++){ let li = document.createElement('li'); oUl.appendChild(li); if(numArr[i]==',') li.innerHTML=','; else li.innerHTML='<p>'+numArr[i]+'</p><p></p>', li.className='num', li.deg=0, aNum.push(li); }; setInterval(function(){ let changeNum=number+1+''; let changeArr = addComma(changeNum), difference=changeArr.length-numArr.length; if(difference){ for(let i=0;i<difference;i++){ let li = document.createElement('li'); oUl.insertBefore(li,oUl.children[0]); if(changeArr[i]==',') li.innerHTML=','; else li.innerHTML='<p>'+changeArr[i]+'</p><p></p>', li.className='num', li.deg=0, aNum.unshift(li); }; }; number+=''; for(let i=changeNum.length-number.length;i<changeNum.length;i++){ if(changeNum[i]==number[i])continue; let deg = aNum[i].deg; aNum[i].deg=deg=deg+180; let index=(deg/180)%2; aNum[i].children[index].innerHTML=changeNum[i]; aNum[i].style.transform='rotateY('+deg+'deg)'; }; number=Number(changeNum); numArr=changeArr; },2000); function addComma(num){ //Add a bean number for every three digits return (num || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,'); }; </script> The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. |
<<: Introduction to the use of data custom attributes in HTML and plug-in applications
>>: Semantics: Is Html/Xhtml really standards-compliant?
MySQL and connection related timeouts Preface: To...
Preface WeChat Mini Programs provide new open cap...
Preface Since errors always occur, record the pro...
Or write down the installation process yourself! ...
Table of contents Preface What situations can cau...
Deploy the project to the project site test envir...
Preparation First, you need to download nodejs, w...
Solution function mergeImgs(list) { const imgDom ...
1. Horizontal center Public code: html: <div c...
This article example shares the specific code of ...
AI image cutting needs to be coordinated with PS....
The effect is very simple, just copy the following...
Join query A join query refers to a matching quer...
Table of contents Registering Components Adding C...
Detailed example of removing duplicate data in My...