How we can create a creative submit button using HTML CSS JavaScript? Solution: See this CSS Submit Button Animation With JavaScript, Submit Button Inspiration.
Previously I have shared many types of buttons, but this is something different because it’s a submit button with animation. Basically, submit button animation shows the progress and indicates when the progress done. After that, it will redirect to the target page which is set on action complete.
Today you will learn to create two types of submit buttons and will get inspiration to create your own. Basically, there is two different types of submit buttons with different animations. The first one is with round circle progress and second is with circle dotted progress, also the first one has a progress bar in the downside of the buttons.
So, Today I am sharing CSS Submit Button Animation With JavaScript. There I have used pure JavaScript for adding and removing class names to elements, there is not any kind of library or framework. These kinds of submit buttons you can see in modern apps and websites, you can put these two buttons on your project.
If you are thinking now how this submit buttons actually are, then see the preview given below.
Preview Of Button Animations
See this video preview to getting an idea of how this animation looks like.
Now you can see this visually, you also can see it live by pressing the button given above. If you like this, then get the source code of its.
You May Also Like:
- CSS Button Hover Effects
- Tooltip or Hint Effects
- Full Page Intro & Navigation
- Text Animation Effects CSS
CSS Submit Button Animation With JavaScript Source Code
Before sharing source code, let’s talk about it. First I have created some divs, headings, and span for creating buttons and their parts using HTML. There are two buttons I gave class name with numbers like 1 and 2, that will help to style the targeted button. There I have used the font-awesome library for the tick icon and linked it in the HTML file.
Now using CSS I have placed all the elements in the right place, as you can see in the preview. After that, I have created all the animations using CSS transition command and other basic commands. For the icons, I have put font-awesome as a font family and placed Unicode in the CSS content command. Many other things had done with CSS you will understand by seeing the codes.
JavaScript working here to adding and removing CSS class names to visualize the animation. Here I have used JavaScript DOM elements to create the program (info). Left all other things you will understand after getting the codes, I can’t explain all in writing. For creating this program you have to create 3 files. First for HTML, second for CSS, and the third for JavaScript. Follow the steps to creating this without any error.
index.html
Create an HTML file named ‘index.html‘ and put these codes given below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
<!DOCTYPE html> <!-- Code By Webdevtrick ( https://webdevtrick.com )--> <html lang="en" > <head> <meta charset="UTF-8"> <title>Submit Button Animation | Webdevtrick.com</title> <link href="https://fonts.googleapis.com/css?family=Karla:400,700&display=swap" rel="stylesheet"> <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/all.min.css'> <link rel="stylesheet" href="style.css"> </head> <body> <div class="content"> <h2 class="title">Click Again To Restart</h2> <div class="inner"> <div class="submit-buttons"> <div class="buttonsBlock"> <h4 class="buttonsTitle">No 1</h4> <div class="submit-buttons__content"> <button class="submit-button submit-button--1" type="submit" title="Submit"> <span class="submit-button__pending submit-button__pending--1"></span> <span class="submit-button__text submit-button__text--1">Submit</span> <span class="submit-button__loaded submit-button__loaded--1"> <span>Success!</span></span> </button> </div> </div> <div class="buttonsBlock"> <h4 class="buttonsTitle">No 2</h4> <div class="submit-buttons__content"> <button class="submit-button submit-button--2" type="submit" title="Submit"> <span class="submit-button__pending submit-button__pending--2"><span class="submit-button__pending-loader--2"></span></span> <span class="submit-button__text submit-button__text--2">Submit</span> <span class="submit-button__loaded submit-button__loaded--2"></span> </button> </div> </div> </div> </div> </div> <script src="function.js"></script> </body> </html> |
style.css
Now create a CSS file named ‘style.css‘ and put these codes given here.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
/* Code By Webdevtrick ( https://webdevtrick.com ) */ * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: 'Karla', sans-serif; font-size: 16px; color: #2c2c2c; margin-top: 15%; } body a { color: inherit; text-decoration: none; } .btn { transition-property: all; transition-duration: 0.2s; transition-timing-function: linear; transition-delay: 0s; padding: 10px 20px; display: inline-block; margin-right: 10px; background-color: #fff; border: 1px solid #2c2c2c; border-radius: 3px; cursor: pointer; outline: none; } .btn:last-child { margin-right: 0; } .btn:hover, .btn.js-active { color: #fff; background-color: #2c2c2c; } .header { max-width: 500px; margin: 50px auto; text-align: center; } .header__title { margin-bottom: 30px; } .content { max-width: 700px; width: 95%; margin: 0 auto 40px; } .title { margin-bottom: 40px; font-size: 20px; text-align: center; } .submit-buttons { display: flex; justify-content: space-around; flex-wrap: wrap; } .buttonsBlock { margin-bottom: 40px; } .buttonsTitle { margin-bottom: 20px; text-align: center; } .submit-button { position: relative; display: flex; align-items: center; justify-content: center; width: 200px; height: 54px; font-size: 14px; font-weight: 700; color: #fff; text-transform: uppercase; letter-spacing: 1.44px; box-shadow: 0px 16px 35px 0 rgba(0, 0, 0, 0.25); outline: none; border: none; overflow: hidden; cursor: pointer; } .submit-button__pending, .submit-button__loaded { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-image: inherit; opacity: 0; visibility: hidden; } .submit-button--1 { background-image: linear-gradient(to right bottom, #00c3ff 1%, #ffff1c); } @keyframes pending-circle { 0% { transform: rotate(0); } 100% { transform: rotate(360deg); } } .submit-button__pending--1 { display: block; } .submit-button__pending--1:before { position: absolute; top: 0; left: 0; display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; font-family: "Font Awesome 5 Free"; font-size: 1.6rem; content: '\f110'; } .submit-button__pending--1:after { position: absolute; left: 0; bottom: 0; display: block; width: 100%; height: 4px; content: ''; transform: scaleX(0); transform-origin: left center; background-image: linear-gradient(to right bottom, #ffff1c 1%, #00c3ff); background-size: 100%; } .submit-button__pending--1.js-active { transition-property: all; transition-duration: 0.1s; transition-timing-function: linear; transition-delay: 0.3s; opacity: 1; visibility: visible; } .submit-button__pending--1.js-active:before { animation: pending-circle 1s infinite; } .submit-button__pending--1.js-active:after { transition-property: all; transition-duration: 1.7s; transition-timing-function: cubic-bezier(0, 0, 0.97, 0.13); transition-delay: 0.1s; transform: scaleX(1); } .submit-button__text--1.js-active { transition-property: all; transition-duration: 0.3s; transition-timing-function: linear; transition-delay: 0s; opacity: 0; visibility: hidden; } .submit-button__loaded--1 { display: flex; align-items: center; justify-content: center; } .submit-button__loaded--1:before { margin-right: 10px; font-family: "Font Awesome 5 Free"; font-size: 1.4rem; content: '\f00c'; transform: translate(-10px, -2px); } .submit-button__loaded--1 span { transform: translateX(10px); } .submit-button__loaded--1.js-active { transition: opacity .1s linear 2.1s; opacity: 1; visibility: visible; } .submit-button__loaded--1.js-active:before { transition-property: all; transition-duration: 0.2s; transition-timing-function: linear; transition-delay: 2.15s; transform: translate(0, -2px); } .submit-button__loaded--1.js-active span { transition-property: all; transition-duration: 0.2s; transition-timing-function: linear; transition-delay: 2.15s; transform: translateX(0); } .submit-button--2 { background-image: linear-gradient(to right bottom, #4ecdc4 1%, #556270); } @keyframes pending-loader-circles { 0% { opacity: .3; } 100% { opacity: 1; } } @keyframes pending-loader-moving { 0% { transform: translateY(0); } 100% { transform: translateY(50px); } } .submit-button__pending--2 { display: flex; align-items: center; justify-content: center; } .submit-button__pending--2:before, .submit-button__pending--2:after, .submit-button__pending--2 span { position: relative; display: block; margin-right: 5px; width: 10px; height: 10px; background-color: #fff; border-radius: 50%; opacity: .3; } .submit-button__pending--2:before, .submit-button__pending--2:after { content: ''; } .submit-button__pending--2:before { animation-delay: 0s; } .submit-button__pending--2 span { animation-delay: .4s; } .submit-button__pending--2:after { animation-delay: .8s; } .submit-button__pending--2.js-active { transition-property: all; transition-duration: 0.1s; transition-timing-function: linear; transition-delay: 0.3s; opacity: 1; visibility: visible; } .submit-button__pending--2.js-active:before { animation: pending-loader-circles .8s linear infinite alternate, pending-loader-moving .2s linear 2s 1 forwards; } .submit-button__pending--2.js-active span { animation: pending-loader-circles .8s linear .4s infinite alternate, pending-loader-moving .2s linear 2.1s 1 forwards; } .submit-button__pending--2.js-active:after { animation: pending-loader-circles .8s linear .8s infinite alternate, pending-loader-moving .2s linear 2.2s 1 forwards; } .submit-button__text--2.js-active { transition-property: all; transition-duration: 0.3s; transition-timing-function: linear; transition-delay: 0s; opacity: 0; visibility: hidden; } .submit-button__loaded--2 { display: flex; align-items: center; justify-content: center; } .submit-button__loaded--2:before { display: block; width: 30px; height: 30px; content: ''; transform: rotate(0); border: 2px solid transparent; border-radius: 50%; } .submit-button__loaded--2:after { position: absolute; top: 50%; left: 50%; display: block; font-family: "Font Awesome 5 Free"; font-size: .9rem; content: '\f00c'; transform: translate(-50%, -50%); opacity: 0; } .submit-button__loaded--2.js-active { transition-property: all; transition-duration: 0.1s; transition-timing-function: linear; transition-delay: 2.2s; opacity: 1; visibility: visible; } .submit-button__loaded--2.js-active:before { transition: transform .4s linear 2.3s, border-top-color .1s linear 2.3s, border-right-color .1s linear 2.4s, border-bottom-color .1s linear 2.5s, border-left-color .1s linear 2.6s; transform: rotate(360deg); border-color: #fff; } .submit-button__loaded--2.js-active:after { transition-property: all; transition-duration: 0.2s; transition-timing-function: linear; transition-delay: 0.6s; opacity: 1; } |
function.js
The final step, create a JavaScript file named ‘function.js‘ and put the codes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
// Code By Webdevtrick ( https://webdevtrick.com ) const DOM = { submitBtn: '.submit-button', submitPending: '.submit-button__pending', submitText: '.submit-button__text', submitLoaded: '.submit-button__loaded' }; //find exact children of the button const findChildren = elem => { return [ elem.querySelector(DOM.submitPending), elem.querySelector(DOM.submitText), elem.querySelector(DOM.submitLoaded)]; }; //find node parent function const findParent = (elem, referenceElem) => { const className = referenceElem.slice(0, referenceElem.length); let ind = true; while (ind) { if (elem.classList.contains(className)) { break; } else { elem = elem.parentNode; } } return elem; }; //onclick function for buttons document.querySelectorAll(DOM.submitBtn).forEach(elem => { elem.addEventListener('click', event => { let clickedElem = findParent(event.target, 'submit-button'); const innerChildren = findChildren(clickedElem); //adding active class if (!clickedElem.classList.contains('js-active')) { clickedElem.classList.add('js-active'); innerChildren.forEach(elem => { elem.classList.add('js-active'); }); } else { //toggling or restart part clickedElem.classList.remove('js-active'); innerChildren.forEach(elem => { elem.classList.remove('js-active'); }); } }); }); |
That’s It. Now you have successfully created CSS Submit Button Animation With JavaScript, Submit Button Inspiration. If you have any doubt or question comment down below.
Thanks For Visiting, Keep Visiting.