HTML CSS SVG确定电子邮件输入框邮件格式是否正确 网页教程 cid1163

html and css

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>animated email input box</title>
  6. <style>
  7. body {
  8. background-color: #485461;
  9. background-image: linear-gradient(315deg, #485461 0%, #28313b 74%);
  10. height: 100vh;
  11. font-family: 'Roboto Mono', monospace;
  12. }
  13. *:focus {outline: none;}
  14. .wrap {
  15. height: 100%;
  16. width: 100%;
  17. overflow: hidden;
  18. padding: 15px;
  19. }
  20. .form-wrap {
  21. position: relative;
  22. height: 50px;
  23. width: 400px;
  24. margin: 100px auto 0;
  25. }
  26. input {
  27. color: #fff;
  28. position: absolute;
  29. width: 100%;
  30. height: 100%;
  31. left: 0;
  32. padding-top: 5px;
  33. border: none;
  34. font-size: 1.5em;
  35. font-weight: 200;
  36. background: none;
  37. opacity: 0;
  38. font-family: 'Roboto Mono', monospace;
  39. transition: all 0.5s ease;
  40. }
  41. .active input{
  42. opacity: 1;
  43. transition: all 0.5s ease 0.5s;
  44. }
  45. svg {
  46. position: absolute;
  47. left: 0;
  48. top: 100%;
  49. overflow: visible;
  50. fill: none;
  51. z-index: 5;
  52. }
  53. label {
  54. color: #fff;
  55. position: absolute;
  56. top: 15px;
  57. font-size: 1.3em;
  58. transition: all 0.5s ease;
  59. }
  60. .active label {
  61. top: 0px;
  62. font-size: 1.6em;
  63. color: #FF5252;
  64. transition: all 0.5s ease 0.6s;
  65. }
  66. svg path {
  67. stroke: #fff;
  68. stroke-width: 3px;
  69. }
  70. .active + svg path {
  71. stroke: #FF5252;
  72. transition: stroke 0.4s ease 0.6s;
  73. }
  74. .input {
  75. height: 100%;
  76. width: 100%;
  77. position: relative;
  78. overflow: hidden;
  79. }
  80. .input:before {
  81. content: "";
  82. position: absolute;
  83. height: 26px;
  84. width: 3px;
  85. right: 15px;
  86. bottom: -50px;
  87. background-color: transparent;
  88. transform-origin: inherit;
  89. transform: rotate(0deg);
  90. transition: transform 0.4s ease , bottom 0.4s ease 0.3s, background-color 0.2s ease 0.6s ;
  91. }
  92. .input:after {
  93. content: "";
  94. position: absolute;
  95. height: 26px;
  96. width: 3px;
  97. right: 15px;
  98. bottom: -50px;
  99. visibility: hidden;
  100. background-color: transparent;
  101. transform-origin: inherit;
  102. transform: rotate(0deg);
  103. transition: transform 0.4s ease, visibility 0.4s ease, bottom 0.4s ease 0.3s, background-color 0.2s ease 0.6s, height 0.2s ease 0.6s;
  104. }
  105. .valid:before {
  106. bottom: 10px;
  107. right: 16px;
  108. visibility: visible;
  109. background-color: #4CAF50 ;
  110. transform-origin: inherit;
  111. transform: rotate(40deg);
  112. transition: bottom 0.4s ease, transform 0.4s ease 0.3s;
  113. }
  114. .valid:after {
  115. bottom: 10px;
  116. height: 15px;
  117. visibility: visible;
  118. background-color: #4CAF50;
  119. transform-origin: inherit;
  120. transform: rotate(-45deg);
  121. transition: bottom 0.4s ease, visibility 0.4s ease 0.3s, transform 0.4s ease 0.3s;
  122. }
  123. .invalid:before {
  124. bottom: 10px;
  125. visibility: visible;
  126. background-color: #ff5252;
  127. transform: rotate(40deg);
  128. transition: bottom 0.4s ease, transform 0.4s ease 0.3s;
  129. }
  130. .invalid:after {
  131. height: 26px;
  132. bottom: 10px;
  133. visibility: visible;
  134. background-color: #ff5252;
  135. transform: rotate(-45deg);
  136. transition: bottom 0.4s ease, visibility 0.4s ease 0.3s, transform 0.4s ease 0.3s;
  137. }
  138. </style>
  139. </head>
  140. <body>
  141. <br><br><br><br><br><br><br><br><br>
  142. <div class="form-wrap">
  143. <div class="input">
  144. <label for="mail">Email address</label>
  145. <input type="email" name="mail" autocomplete="off">
  146. </div>
  147. <svg>
  148. <path d="M0 1.5h400" fill="none"/>
  149. </svg>
  150. </div>
  151. <script src="snap.svg-min.js"></script>
  152. <script src="scripts.js">
  153. </script>
  154. </body>
  155. </html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>animated email input box</title>
    <style>
    body {
   background-color: #485461;
background-image: linear-gradient(315deg, #485461 0%, #28313b 74%);
        height: 100vh;
  font-family: 'Roboto Mono', monospace;
}

*:focus {outline: none;}

.wrap {
  height: 100%;
  width: 100%;
  overflow: hidden;
  padding: 15px;
}
.form-wrap {
    position: relative;
    height: 50px;
    width: 400px;
    margin: 100px auto 0;

}

input {
  color: #fff;
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  padding-top: 5px;
  border: none;
  font-size: 1.5em;
  font-weight: 200;
  background: none;
  opacity: 0;
    font-family: 'Roboto Mono', monospace;
  transition: all 0.5s ease;
}

.active input{
  opacity: 1;
  transition: all 0.5s ease 0.5s;
}

svg {
  position: absolute;
  left: 0;
  top: 100%;
  overflow: visible;
  fill: none;
  z-index: 5;
}

label {
  color: #fff;
  position: absolute;
  top: 15px;
  font-size: 1.3em;
  transition: all 0.5s ease;
}

.active label {
  top: 0px;
  font-size: 1.6em;
  color: #FF5252;
  transition: all 0.5s ease 0.6s;
}

svg path {
  stroke: #fff;
  stroke-width: 3px;
}

.active + svg path {
  stroke: #FF5252;
  transition: stroke 0.4s ease 0.6s;
}

.input {
  height: 100%;
  width: 100%;
  position: relative;
  overflow: hidden;
}
.input:before {
    content: "";
    position: absolute;
    height: 26px;
    width: 3px;
    right: 15px;
    bottom: -50px;
      background-color: transparent;
   transform-origin: inherit;
    transform: rotate(0deg);
    transition: transform 0.4s ease , bottom 0.4s ease 0.3s, background-color 0.2s ease 0.6s ;
}

.input:after {
    content: "";
    position: absolute;
    height: 26px;
    width: 3px;
    right: 15px;
    bottom: -50px;
    visibility: hidden;
     background-color: transparent;
     transform-origin: inherit;
    transform: rotate(0deg);
    transition: transform 0.4s ease, visibility 0.4s ease, bottom 0.4s ease 0.3s, background-color 0.2s ease 0.6s, height 0.2s ease 0.6s;
}

.valid:before {
  bottom: 10px;
   right: 16px;
  visibility: visible;
   background-color: #4CAF50 ;
     transform-origin: inherit;
  transform: rotate(40deg);
  transition: bottom 0.4s ease, transform 0.4s ease 0.3s;
  }

.valid:after {
  bottom: 10px;
   height: 15px;
  visibility: visible;
  background-color: #4CAF50;
    transform-origin: inherit;
  transform: rotate(-45deg);
  transition: bottom 0.4s ease, visibility 0.4s ease 0.3s, transform 0.4s ease 0.3s;
  }

  .invalid:before {
    bottom: 10px;
    visibility: visible;
    background-color: #ff5252;
    transform: rotate(40deg);
    transition: bottom 0.4s ease, transform 0.4s ease 0.3s;
    }

  .invalid:after {
    height: 26px;
    bottom: 10px;
    visibility: visible;
    background-color: #ff5252;
    transform: rotate(-45deg);
    transition: bottom 0.4s ease, visibility 0.4s ease 0.3s, transform 0.4s ease 0.3s;
    }
    </style>
</head>
<body>
   <br><br><br><br><br><br><br><br><br>
    <div class="form-wrap">
  <div class="input">
<label for="mail">Email address</label>
<input type="email" name="mail" autocomplete="off">
</div>
 <svg>
  <path d="M0 1.5h400" fill="none"/>
</svg>
</div>
<script src="snap.svg-min.js"></script>
<script src="scripts.js">
   
    </script>
</body>
</html>

js

  1. 'use strict';
  2. var textInput = document.querySelector('input');
  3. var textPath;
  4. var textDown = function() {
  5. textPath.animate({
  6. d: "M0 1.5c150 40 300 30 400 0"
  7. }, 150, mina.easeout);
  8. };
  9. var textUp = function() {
  10. textPath.animate({
  11. d: "M0 1.5c150-18 300-18 400 0"
  12. }, 150, mina.easein);
  13. };
  14. var textSame = function() {
  15. textPath.animate({
  16. d: "M0 1.5h400"
  17. }, 200, mina.easein);
  18. };
  19. var textRun = function() {
  20. setTimeout(textDown, 200);
  21. setTimeout(textUp, 400);
  22. setTimeout(textSame, 600);
  23. };
  24. (function() {
  25. textInput.addEventListener('focus', function() {
  26. var svgText = Snap('svg');
  27. var parentDiv = this.parentElement;
  28. textPath = svgText.select('path');
  29. parentDiv.classList.add('active');
  30. textRun();
  31. this.addEventListener('blur', function() {
  32. var rg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.]{3,9})+\.([A-Za-z]{2,4})$/;
  33. this.value == 0 ? parentDiv.classList.remove('active') : null;
  34. !rg.test(this.value) && this.value != 0 ?
  35. (parentDiv.classList.remove('valid'), parentDiv.classList.add('invalid'), parentDiv.style.transformOrigin = "center") :
  36. rg.test(this.value) && this.value != 0 ?
  37. (parentDiv.classList.add('valid'), parentDiv.classList.remove('invalid'), parentDiv.style.transformOrigin = "bottom") : null;
  38. });
  39. parentDiv.classList.remove('valid', 'invalid')
  40. });
  41. })();
 'use strict';
var textInput = document.querySelector('input');
var textPath;
var textDown = function() {
  textPath.animate({
    d: "M0 1.5c150 40 300 30 400 0"
  }, 150, mina.easeout);
};
var textUp = function() {
  textPath.animate({
    d: "M0 1.5c150-18 300-18 400 0"
  }, 150, mina.easein);
};
var textSame = function() {
  textPath.animate({
    d: "M0 1.5h400"
  }, 200, mina.easein);
};
var textRun = function() {
  setTimeout(textDown, 200);
  setTimeout(textUp, 400);
  setTimeout(textSame, 600);
};
(function() {
  textInput.addEventListener('focus', function() {
    var svgText = Snap('svg');
    var parentDiv = this.parentElement;
    textPath = svgText.select('path');
    parentDiv.classList.add('active');
    textRun();
    this.addEventListener('blur', function() {
      var rg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.]{3,9})+\.([A-Za-z]{2,4})$/;
      this.value == 0 ? parentDiv.classList.remove('active') : null;
      !rg.test(this.value) && this.value != 0 ?
        (parentDiv.classList.remove('valid'), parentDiv.classList.add('invalid'), parentDiv.style.transformOrigin = "center") :
        rg.test(this.value) && this.value != 0 ?
        (parentDiv.classList.add('valid'), parentDiv.classList.remove('invalid'), parentDiv.style.transformOrigin = "bottom") : null;
    });
    parentDiv.classList.remove('valid', 'invalid')
  });
})();

 在线演示


让链接同时具备两种打开方式
获取源码: email validated
下载数:36人次, 文件大小: 30.2 KB, 上传日期: 2021年-6 月-06日

公众号回复:gcode  获取解压密码

qrcode_for_gh_6ea2c28a1709_258 (1)

2,138 人查阅

类似文章