Button activates SVG animation

Currently, I am working on an animation for a button using SVG. The animation utilizes the classes .is-loading and .is-success. However, when I click on the button, the animation does not execute as expected. I'm having trouble identifying the error within the animation.

Below is the JavaScript code:

var name = document.getElementById("nome_field");
var height = document.getElementById("height_field");
var weight = document.getElementById("weight_field");
const result = document.getElementById("submit_field");

result.addEventListener('click', function btn ()  {
  result.classList.add('is-loading');

  setTimeout( () => {
    result.classList.add('is-success');
    result.classList.remove('is-loading');
    result.removeEventListener('click', btn);
  }, 4000);
});

Here is the corresponding CSS code:

.submit_btn{
  position: absolute;
  top: 5px;
  right: 110px;
  background: none;
  color: #000;
  border: 1px solid #45981B;
  border-radius: 40px;
  box-shadow: 0 0 0 0 rgba(69, 152, 27, 0.5);
  cursor: pointer;
  height: 45px;
  width: 10px;
  outline: none;
  padding: 15px 70px;
  transition: background, padding 500ms ease-in-out;
}
span{
  font-size: 15px;
  position: absolute;
  top: 12px;
  left: 36px;
}
.submit_btn.is-loading {
  animation: pulse 1.5s infinite;
  padding: 15px 7px;
}
.submit_btn.is-success {
  background: #45981B;
  padding: 15px 7px;
}

svg {
  width: 0;
  height: 0;
}

.is-success svg {
  height: 30px;
  width: 30px;
}

.check {
  stroke-dasharray: 130px 130px;
  stroke-dashoffset: 130px;
  transition: stroke-dashoffset 500ms ease-in-out;
}

.is-loading span,
.is-success span {
  display: none;
}

.is-success .check {
  stroke-dashoffset: 0px;
}

@keyframes pulse {
  0% {
    transform: scale(.9);
  }
  70% {
    transform: scale(1);
    box-shadow: 0 0 0 50px rgba(69, 152, 27, 0);
  }
  100% {
    transform: scale(.9);
    box-shadow: 0 0 0 0 rgba(69, 152, 27, 0);
  }
}

Finally, here is the HTML code that contains the button and SVG elements:

<form class="form_submit">
<button type="button" class="btn_clear" class="btn_limpar"> Clear </button>
<button type="button" class="submit_button" class="btn_enviar">
   <svg viewBox="0 0 90.594 59.714">
    <polyline
      class="check"
      fill="none"
      stroke="#FFFFFF"
      stroke-width="10"
      stroke-miterlimit="10"
      points="1.768,23.532 34.415,56.179 88.826,1.768"
    />
  </svg>
  <span> Result </span>  
</button>

Answer №1

There seems to be an issue with the element ID campo_enviar in your JavaScript code as it is not found in the HTML. The code snippet provided highlights this error.

var nome = document.getElementById("campo_nome");
var altura = document.getElementById("campo_altura");
var peso = document.getElementById("campo_peso");
const resultado = document.getElementById("campo_enviar");

resultado.addEventListener('click', function btn ()  {
  resultado.classList.add('is-loading');

  setTimeout( () => {
    resultado.classList.add('is-success');
    resultado.classList.remove('is-loading');
    resultado.removeEventListener('click', btn);
  }, 4000);
});
.btn_enviar{
  position: absolute;
  top: 5px;
  right: 110px;
  background: none;
  color: #000;
  border: 1px solid #45981B;
  border-radius: 40px;
  box-shadow: 0 0 0 0 rgba(69, 152, 27, 0.5);
  cursor: pointer;
  height: 45px;
  width: 10px;
  outline: none;
  padding: 15px 70px;
  transition: background, padding 500ms ease-in-out;
}
span{
  font-size: 15px;
  position: absolute;
  top: 12px;
  left: 36px;
}
.btn_enviar.is-loading {
  animation: pulse 1.5s infinite;
  padding: 15px 7px;
}
.btn_enviar.is-success {
  background: #45981B;
  padding: 15px 7px;
}

svg {
  width: 0;
  height: 0;
}

.is-success svg {
  height: 30px;
  width: 30px;
}

.check {
  stroke-dasharray: 130px 130px;
  stroke-dashoffset: 130px;
  transition: stroke-dashoffset 500ms ease-in-out;
}

.is-loading span,
.is-success span {
  display: none;
}

.is-success .check {
  stroke-dashoffset: 0px;
}

@keyframes pulse {
  0% {
    transform: scale(.9);
  }
  70% {
    transform: scale(1);
    box-shadow: 0 0 0 50px rgba(69, 152, 27, 0);
  }
  100% {
    transform: scale(.9);
    box-shadow: 0 0 0 0 rgba(69, 152, 27, 0);
  }
}
<form class="formulario_btn">
<button type="button" class="btn_limpar" class="btn_limpar"> Limpar </button>
<button type="button" class="btn_enviar" class="btn_enviar">
   <svg viewBox="0 0 90.594 59.714">
    <polyline
      class="check"
      fill="none"
      stroke="#FFFFFF"
      stroke-width="10"
      stroke-miterlimit="10"
      points="1.768,23.532 34.415,56.179 88.826,1.768"
    />
  </svg>
  <span> Resultado </span>  
</button>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

JavaScript Ajax request lags significantly in Internet Explorer, while it executes instantly in Firefox

So I have this jQuery .ajax() call set up to retrieve a List<string> of IP addresses from a specific subnet. I'm using a [WebMethod] on an .aspx page to handle the request and ASP.NET's JSON serializer to format the response for my Javascri ...

Exploring innovative designs for asynchronous JavaScript programming

Imagine you have an Express app and you need to retrieve data from a database to display on the frontend. There's a function in your code that looks like this (using node-mysql for handling database queries) exports.getData = function() { ...

Problems with CSS text scrolling

We have a client who wants a marquee-style scrolling text banner, and I tried using CSS animations to achieve it. However, I encountered some quirks that I'm struggling to fix. If you want to take a look at the issue, here is the link: https://jsfidd ...

Angular 2 Component attribute masking

In my Angular 2 component called Foobar, I have defined a property named foobar: import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-foobar', templateUrl: './foobar.component ...

Email Form Application: Utilizing NodeJs and Express - Error: URL Not Found /

I'm encountering a "cannot GET" error whenever I try to run my application on a live server using VS Code. My assumption is that the issue lies within my routing configuration, but I'm struggling to identify the exact problem. Any assistance woul ...

Immediate display of collapsed/toggle menu in a Bootstrap navbar

I have created a bootstrap responsive navigation menu that collapses into a box when the page is resized. It's a standard menu with bootstrap, but I'm facing an issue where the menu automatically appears when the page gets small instead of needin ...

Import HTML file into email message

After successfully creating a script to send HTML emails, I encountered an issue. I have the email content stored in a separate HTML file, which is then read using a while loop and fgets(). However, I need to find a way to pass variables into the HTML. For ...

Problem with automatic saving of workspaces in DBeaver

Currently using DBeaver with Oracle server and encountering a recurring error related to workspace save. I have searched online for a solution, but all results seem to focus on meta data explanations. As someone new to DBeaver, I would greatly appreciate ...

Tips for executing an href action within an iframe (using colorbox) following the completion of a PHP script

I am currently trying to figure out the best way to make a link open in an iframe (using colorbox) after a php script has finished processing. The reason behind this necessity is that within the php script, I generate a png image from a canvas element on t ...

Utilizing JQuery toggle feature to display extra content

Having some trouble with my JQuery toggle/collapse function. I added my own class "timelineEventWide" but it's not working as expected. As a JavaScript beginner, could someone please help me with the correct syntax? Thank you! e(".expandAll").toggle( ...

Establishing pathways in Angular 2

I'm currently working on configuring a route so that whenever I visit http://localhost:8080/user/beta/, it will redirect to http://localhost:8080/user/beta/#spreadsheet. The goal is to display the spreadsheet view, but instead of achieving that result ...

Javascript Mouse Events Not Functioning Properly with Three.JS Scene Components

Currently feeling quite perplexed (probably due to fatigue from working on this at an inopportune time). I'm in the midst of trying to configure my three.js application to trigger distinct functions based on different mouse events when the cursor hove ...

Can someone help me locate the file using the inspect element feature?

Today, I encountered a small issue on my website that I wanted to fix. Although I was able to make the necessary changes using Inspect Element, I couldn't locate the file where it needed to be changed. The website in question is gesher-jds.org/giving. ...

Incorporating React into an already existing webpage and accessing URL parameters within a .js file

Following the official guidelines: To include React in a website, visit https://reactjs.org/docs/add-react-to-a-website.html I have created a file named test.html with the following content: <!DOCTYPE html> <html> <head> < ...

What is the best way to customize the lower border color of a collapsed Bootstrap navbar with an inverse design

Discussing this issue.. I am noticing two distinct colors. One is darker than the background shade and the other is lighter than the background shade. How can these be set? https://i.sstatic.net/Y39IZ.jpg <nav class="navbar navbar-inverse"> <d ...

How can I make a method in VueJS wait to execute until after rendering?

There is a button that triggers the parse method. parse: function() { this.json.data = getDataFromAPI(); applyColor(); }, applyColor: function() { for (var i=0; i<this.json.data.length; i++) { var doc = document.getElementById(t ...

Strange behavior of Lambda function in Typescript

Within a larger class, I'm working with the following code snippet: array.map(seq => this.mFunction(seq)); After compiling using the tsc command, it becomes: array.map(function (seq) { return _this.mFunction(seq); }); Everything seems fine so f ...

Tips for updating the date format in Material UI components and input fields

Is there a way to customize the date format in Material UI for input text fields? I am struggling to format a textField with type 'date' to display as 'DD/MM/YYYY'. The available options for formatting seem limited. It would be helpful ...

Edit the contents within HTML strings without altering the HTML structure

If I have a string of HTML, it might look something like this... <h2>Header</h2><p>all the <span class="bright">content</span> here</p> I am interested in manipulating the string by reversing all the words. For example ...

Stylist in Visual Studio Code for React applications

Whenever I try to save or format my React code using Ctrl + Shift + F, the formatting of the code below seems unusual. Is there a way to fix this issue? The original code is as follows: import logo from './logo.svg'; import './App.css&apos ...