Home > Enterprise >  loading button with bootstrap 5
loading button with bootstrap 5

Time:01-12

i'm trying to develop a button with a loading message. in html page i have

<div >
   <button id="connectMetamaskBtn"  type="button"
           style="margin-top: 5%; width: 400px;"
           loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Connecting...">
           Connect to Metamask
              <img  src="assets/images/icons8-metamask-logo-48.png" width="25px" />
   </button>
</div>

and in app.js

$("#connectMetamaskBtn").on("click", async () => {
  var $this = $(this);
  $this.button('loading');
  try {
    provider = new ethers.providers.Web3Provider(window.ethereum);

    // MetaMask requires requesting permission to connect users accounts
    await provider.send("eth_requestAccounts", []);
    await startApp(provider);
  }
  catch (e) {
    $this.button('reset');
    $("#error")
      .text(`An error occured: ${e.message || e}`)
      .show();
  }
});

The loading doesn't work.. any idea ? Thx

CodePudding user response:

use this button:

$('.btn').on('click', function() {
    var $this = $(this);
  $this.button('loading');
    setTimeout(function() {
       $this.button('reset');
   }, 8000);
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css">


<div style="margin:3em;">
<button type="button"  id="load2" data-loading-text="<i class='fa fa-spinner fa-spin '></i> Processing Order">Submit Order</button>
</div>


<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.2.0/js/bootstrap.min.js"></script>

  • Related