js+svg实现文件选择上传带进度动画效果代码

代码语言:html

所属分类:上传

代码描述:js+svg实现文件选择上传带进度动画效果代码效果代码

代码标签: js svg 文件 选择 上传 进度 动画

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  
  
  
<style>
@import url("https://fonts.googleapis.com/css?family=Roboto:400,400i,700");
/* ------------------------------
Upload button styling
------------------------------ */
.upload {
  --color-black-softest: #485461;
  /* softer black */
  --color-black-soft: #363F48;
  /* softer black */
  --color-black-hard: #2d353c;
  /* harder black */
  --color-black-hardest: #21282e;
  /* hardest black */
  --color-green-light: #65cca9;
  /* light green */
  --color-green: #29b586;
  /* medium green */
  --ease-in-out-quartic: cubic-bezier(0.645, 0.045, 0.355, 1);
  position: relative;
  display: inline-flex;
  background: #485461;
  border-radius: 10px;
  box-shadow: 0 1.7px 1.4px rgba(0, 0, 0, 0.02), 0 4px 3.3px rgba(0, 0, 0, 0.028), 0 7.5px 6.3px rgba(0, 0, 0, 0.035), 0 13.4px 11.2px rgba(0, 0, 0, 0.042), 0 25.1px 20.9px rgba(0, 0, 0, 0.05), 0 60px 50px rgba(0, 0, 0, 0.07);
  overflow: hidden;
  transform: rotate(0);
}
.upload-info {
  display: flex;
  align-items: center;
  padding: 16px;
  margin-right: 40px;
  fill: #fff;
  color: #fff;
}
.upload-filename {
  padding-left: 8px;
  transition: opacity 300ms ease;
}
.upload-filename.inactive {
  opacity: 0.6;
}
.upload-button {
  position: relative;
  margin: 0;
  font-size: 100%;
  padding: 0 8px;
  font-family: inherit;
  background: none;
  border: none;
  border-radius: inherit;
  outline: none;
}
.upload-button-text {
  padding: 8px 16px;
  color: white;
  background-color: var(--color-green);
  border-radius: inherit;
  outline: none;
  cursor: pointer;
  transition: background-color 200ms ease, box-shadow 300ms ease;
}
.upload-button-text:hover, .upload-button-text:focus {
  background-color: var(--color-green-light);
}
.upload-button-text.inactive {
  background-color: rgba(255, 255, 255, 0.38);
  cursor: not-allowed;
}
.upload-hint {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  color: white;
  transform: translateY(100%);
}
.upload-progress {
  position: absolute;
  top: 90%;
  left: -100%;
  width: 100%;
  height: 100%;
  color: white;
  background: linear-gradient(270deg, #87e0c2 0%, #65cca9 50%, #26b082 100%);
  transform-origin: left;
}
.upload.uploading .upload-button-text {
  animation: fade-up-out 0.4s 0.4s forwards, button-pulse 500ms forwards;
}
.upload.uploading .upload-info > * {
  animation: fade-up-out 0.4s 0.4s forwards;
}
.upload.uploading .upload-hint {
  animation: fade-up-in 0.4s 0.8s forwards;
}
.upload.uploading .upload-progress {
  animation: load-right 2s 1s var(--ease-in-out-quartic) forwards;
  animation-iteration-count: infinite;
}

@keyframes button-pulse {
  from {
    box-shadow: 0 0 0 0 var(--color-green-light);
  }
  to {
    box-shadow: 0 0 0 8px rgba(255, 255, 255, 0);
  }
}
@keyframes fade-up-out {
  to {
    opacity: 0;
    transform: translateY(-40%);
  }
}
@keyframes fade-up-in {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@keyframes load-right {
  0% {
    left: -100%;
  }
  50% {
    left: 0;
  }
  100% {
    left: 100%;
  }
}
[type=file] {
  height: 0;
  overflow: hidden;
  width: 0;
  cursor: pointer;
}

.drop-area {
  border: 1px solid var(--color-black-softest);
}
.drop-area.droppable {
  border: 1px dashed rgba(255, 255, 255, 0.6);
}
.drop-area.highlight {
  border: 1px dashed var(--color-green);
}

/* ------------------------------
Styling for the rest of the page
------------------------------ */
body {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  font-family: Roboto, sans-serif;
  background: #2d353c;
  color: #ccc;
}

.wrapper {
  text-align: center;
}
.wrapper .upload-wrapper {
  display: inline-block;
  margin: 2rem auto 0;
}

h1, h2 {
  color: #fff;
  text-align: center;
  letter-spacing: 0.02em;
  margin-bottom: 0.3em;
}
</style>


  
</head>

<body >
  <div class="wrapper">
  <h1>Animated Upload File Button</h1>
  <p>This input supports drag and drop too, try it!</p>
  <div class="upload-wrapper">
    <div class="upload drop-area">
      <div class="upload-info">
        <svg
          t="1581822650945"
          class="clip"
          viewBox="0 0 1024 1024"
          version="1.1"
          xmlns="http://www.w3.org/2000/svg"
          p-id="3250"
          width="20"
          height="20"
        >
          <path
            d="M645.51621918 141.21142578c21.36236596 0 41.79528808 4.04901123 61.4025879 12.06298852a159.71594214 159.71594214 0 0 1 54.26367236 35.87255836c15.84503198 16.07739258 27.76959252 34.13726783 35.78356909 54.13513184 7.86071778 19.30572486 11.76635766 39.80291724 11.76635767 61.53607177 0 21.68371583-3.90563989 42.22045875-11.76635767 61.54101586-8.01397729 19.99291992-19.95831275 38.02807617-35.78356909 54.08569313l-301.39672877 302.0839231c-9.21038818 9.22027564-20.15112281 16.48278832-32.74310277 21.77270508-12.29040503 4.81036401-24.54125953 7.19329834-36.82177783 7.19329834-12.29040503 0-24.56103516-2.38293433-36.85638427-7.19329834-12.63647461-5.28991675-23.53271461-12.55737281-32.7381587-21.77270508-9.55151367-9.58117675-16.69042992-20.44775367-21.50573731-32.57995583-4.7856443-11.61804223-7.15869117-23.91339135-7.15869188-36.9255979 0-13.14074708 2.37304688-25.55474854 7.16363524-37.19256639 4.81036401-11.94927954 11.94927954-22.78619408 21.50079395-32.55029274l278.11614966-278.46221923c6.45172119-6.51104737 14.22344971-9.75421118 23.27563501-9.75421119 8.86.........完整代码请登录后点击上方下载按钮下载查看

网友评论0