Home Web Front-end JS Tutorial Simple example code to implement Ripple button using native js

Simple example code to implement Ripple button using native js

Mar 25, 2017 pm 02:52 PM

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

Simple example code to implement Ripple button using native js

Prepare ingredients (html part)

 <ul id="nav">
  <li>
   <a href=&#39;#&#39;>
    <span>首页</span>
   <span class="circle"></span>
   </a>
  </li>
  <li>
   <a href=&#39;#&#39;>
    <span>我的</span>
   <span class="circle"></span>
   </a>
  </li>
  <li>
   <a href=&#39;#&#39;>
    <span>更多</span>
   <span class="circle"></span>
   </a>
  </li>
 </ul>
Copy after login

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%;}
 }
Copy after login

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(&#39;nav&#39;).querySelectorAll(&#39;li&#39;);
 var circle = document.getElementById(&#39;nav&#39;).querySelectorAll(&#39;.circle&#39;);
   for(var i=0,len = li.length;i<len;i++){
    ((i)=>{
    li[i].addEventListener(&#39;click&#39;,(e)=>{
     circle[i].setAttribute(&#39;class&#39;,&#39;circle act&#39;);
     circle[i].setAttribute(&#39;style&#39;,&#39;top:&#39;+e.layerY+&#39;px;left:&#39;+e.layerX+&#39;px&#39;);
    });

    li[i].addEventListener(&#39;touchend&#39;,()=>{
     circle[i].setAttribute(&#39;class&#39;,&#39;circle&#39;);
    })
    })(i)

   }
Copy after login

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! touchendOnly 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!

Statement of this Website
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

Hot AI Tools

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.

Undress AI Tool

Undress AI Tool

Undress images for free

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

AI-Generated Fake Video Promises to Reward XRP Coin Holders, But It's a Scam AI-Generated Fake Video Promises to Reward XRP Coin Holders, But It's a Scam Oct 22, 2024 am 03:08 AM

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.

Neil DeSilva, Former PayPal Digital Currencies CFO, and Ripple Exploring Partnership to Create Sustainable Blockchain Business Neil DeSilva, Former PayPal Digital Currencies CFO, and Ripple Exploring Partnership to Create Sustainable Blockchain Business Oct 18, 2024 am 12:50 AM

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

Ripple CEO Brad Garlinghouse Discusses Donald Trump's Support for Cryptocurrency, Criticizes SEC's Approach to Crypto Regulation Ripple CEO Brad Garlinghouse Discusses Donald Trump's Support for Cryptocurrency, Criticizes SEC's Approach to Crypto Regulation Nov 09, 2024 pm 06:28 PM

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

Ripple Labs Files Cross-Appeal in Ongoing Legal Struggle with the SEC Ripple Labs Files Cross-Appeal in Ongoing Legal Struggle with the SEC Oct 12, 2024 pm 09:44 PM

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

Ripple Leverages UAE Framework for Dirham-Backed Stablecoin Initiatives Ripple Leverages UAE Framework for Dirham-Backed Stablecoin Initiatives Nov 09, 2024 am 03:58 AM

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.

Ripple CLO Breaks Down Next Steps In US SEC vs XRP Ripple CLO Breaks Down Next Steps In US SEC vs XRP Oct 16, 2024 am 09:04 AM

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 Price Prediction: XRP Is Close to a Key Breakout Level at $0.66, with Potential to Rally Up to $1.50 XRP Price Prediction: XRP Is Close to a Key Breakout Level at $0.66, with Potential to Rally Up to $1.50 Nov 13, 2024 am 12:28 AM

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): Can the XRP coin price break through the $4 mark this quarter? Ripple(XRP): Can the XRP coin price break through the $4 mark this quarter? Mar 04, 2025 am 06:15 AM

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

See all articles