Simple example code to implement Ripple button using native js
This article mainly introduces the native jsimplementation of simple Ripplebutton example code, which has certain reference value. Interested friends can refer to it.
Organize the documents, search out a native js code to implement a simple Ripple button, sort it out and streamline it a little for sharing.
The effect is as shown
Prepare ingredients (html part)
<ul id="nav"> <li> <a href='#'> <span>首页</span> <span class="circle"></span> </a> </li> <li> <a href='#'> <span>我的</span> <span class="circle"></span> </a> </li> <li> <a href='#'> <span>更多</span> <span class="circle"></span> </a> </li> </ul>
Typical menu li layout, insidespan.circle
represents the small circle that pops up when touched.
Prepare auxiliary materials (css part)
#nav { display: flex; } #nav li { position: relative; overflow: hidden; flex: 1; } li a { display: flex; flex-direction: column; justify-content: center; align-items: center; } .circle{ position: absolute; background: rgba(86,187,247,.1); width: 1px; height: 1px; top:50%; left: 50%; border-radius: 50%; } .circle.act{ animation: navCircle .4s; } @keyframes navCircle { from {transform: scale(0);border-radius: 50%;} to {transform:scale(200);border-radius: 50%;} }
My idea is this, give li relative positioning, give the small circle absolute positioning, and then add animation to the small circlenavCircle
, use CSS3 scaling to make it larger. As for why it is 200 times and .4s, after testing, it is more user-friendly. You can also try the other multiples.
Fire cooking (js part)
var li = document.getElementById('nav').querySelectorAll('li'); var circle = document.getElementById('nav').querySelectorAll('.circle'); for(var i=0,len = li.length;i<len;i++){ ((i)=>{ li[i].addEventListener('click',(e)=>{ circle[i].setAttribute('class','circle act'); circle[i].setAttribute('style','top:'+e.layerY+'px;left:'+e.layerX+'px'); }); li[i].addEventListener('touchend',()=>{ circle[i].setAttribute('class','circle'); }) })(i) }
The code is very simple, I believe everyone has guessed it. When clicking li, add class 'act' to the small circle
, and set the starting position of the small circle, when the monitoring touch ends, cancel the class 'act'
, someone must ask, why don't you use touchstart
, ugh , because there is no attribute layerY
, so I couldn’t find it after searching for a long time. And why not use <a href="http://www.php.cn/wiki/127.html" target="_blank">forEach</a>
? Some browsers don’t support it. Tears = =!
friendly reminder! touchend
Only supports mobile terminal
End
I do this part because our Android app has this function, so I want to take a look at h5 How to do it? The initial idea was to make the width and height increase over time, but after implementing it, I felt that the performance was not good, so I thought of directly increasing the multiple. Then this function became perfect and was born. Start enjoying this package!
The above is the detailed content of Simple example code to implement Ripple button using native js. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

An AI-generated fake video is circulating among crypto traders, in which Ripple's co-founder is falsely promising to reward up to 150 million XRP cryptocurrency to existing XRP coin holders.

The new venture could involve XRP and potentially push the altcoin towards $1.

CEO Brad Garlinghouse discussed Donald Trump's support for cryptocurrency, where Trump has positioned himself as a "crypto advocate" during his campaign.

Ripple CEO, Brad Garlinghouse stated that the Company is ready to withstand the legal procedures that are currently going on.

The UAE's framework allows for the issue and use of AED-backed stablecoins for payments. In contrast, stablecoins tied to other currencies can be registered for virtual asset transactions within set guidelines.

Stuart Alderoty has shared the developments of next steps that are to be taken in the ongoing lawsuit between Ripple and the United States Securities and Exchange Commission (SEC).

XRP saw a 19% jump this week as strong market indicators, including reduced selling pressure and increased open interest, point to further bullish movement.

Ripple (XRP) Outlook: Can the altcoin season exceed $4? This article will explore whether Ripple (XRP) can break through the all-time high of $4 in the upcoming altcoin season. Despite the overall cryptocurrency market sluggish, XRP still has upside potential. Can XRP break through $4? Analysts predict XRP will rebound in the coming months, even reaching an all-time high of $4.12 on April 15, up nearly 80%. However, the average forecast price is around $3.12, and April 15 may be just a brief peak. XRP's cooperation with South Korea and the approval process of XRPETF will be key factors affecting its price. South Korea cooperation will increase XRP's market share in South Korea; and the approval of XRPETF will
