原生js实现步骤表单效果
代码语言:html
所属分类:表单美化
代码描述:原生js实现步骤表单效果
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> @import url("https://fonts.googleapis.com/css?family=Pacifico|Roboto"); body { background: #428bca; font-family: 'Roboto', sans-serif; margin: 0; } h1.logo { color: #fff; font-family: 'Pacifico', cursive; font-size: 4em; } h1.end { position: relative; color: #fff; opacity: 0; transition: 0.8s ease-in-out; } #container { height: 100vh; display: flex; flex-direction: column; justify-content: top; align-items: center; } #form-box { background: #fff; position: relative; width: 600px; border-top-right-radius: 5px; border-top-left-radius: 5px; box-shadow: 0 16px 24px 2px rgba(0, 0, 0, 0.1), 0 6px 10px 5px rgba(0, 0, 0, 0.1), 0 8px 10px -5px rgba(0, 0, 0, 0.2); transition: transform 0.1s ease-in-out; } #form-box.close { width: 0; padding: 0; overflow: hidden; transition: 0.8s ease-in-out; box-shadow: 0 16px 24px 2px rgba(0, 0, 0, 0); } #next-btn { position: absolute; right: 20px; bottom: 10px; font-size: 40px; color: #428bca; float: right; cursor: pointer; z-index: 2; } #next-btn:hover { color: #b9d4ec; } #prev-btn { position: absolute; font-size: 18px; left: 30px; top: 12px; z-index: 2; color: #9e9e9e; float: right; cursor: pointer; } #prev-btn:hover { color: #b9d4ec; } #input-group { position: relative; padding: 30px 20px 20px 20px; margin: 10px 60px 10px 10px; opacity: 0; transition: opacity 0.3s ease-in-out; } #input-group input { position: relative; width: 100%; border: none; font-size: 20px; font-weight: bold; outline: 0; background: transparent; box-shadow: none; } #input-group #input-label { position: absolute; pointer-events: none; top: 32px; left: 20px; font-size: 20px; font-weight: bold; transition: 0.2s ease-in-out; } #input-group input:valid + #input-label { top: 6px; left: 42px; margin-left: 0 !important; font-size: 11px; font-weight: normal; color: #9e9e9e; } #input-progress { border-bottom: 3px solid #428bca; width: 0; transition: width 0.6s ease-in-out; } #progress-bar { position: absolute; background: #b9d4ec; height: 10px; width: 0; transition: width 0.5s ease-in-out; } .close #next-btn, .close #prev-btn { color: #fff; } .error #input-progress { border-color: #ff2d26; } .error #next-btn { color: #ff2d26; } @media (max-width: 600px) { #form-box { width: 80%; } } </style> </head> <body> <div id="container"> <h1 class="logo">Fancy Form</h1> <div id="form-box"> <i id="prev-btn" class="fas fa-arrow-left"></i> <i id="next-btn" class="fas fa-arrow-right"></i> <div id="input-group"> <input id="input-field" required> <label id="input-label"></label> <div id="input-progress"></div> </div> <div id="progress-bar"></div> </div> </div> <script> // Questions Array const questions = [ { question: 'Enter Your First Name' }, { question: 'Enter Your Last Name' }, { question: 'Enter Your Email', pattern: /\S+@\S+\.\S+/ }, { question: 'Create A Password', type: 'password' }]; // Transition Times const shakeTime = 100; // Shake Transition Time const switchTime = 200; // Transition Between Questions // Init Position At First Question let position = 0; // Init DOM Elements const formBox = doc.........完整代码请登录后点击上方下载按钮下载查看
网友评论0