|
|

楼主 |
发表于 2023-4-4 08:23
|
显示全部楼层
源码- <style>
- .mama {
- width: 300px;
- height: 40px;
- border: 1px solid darkgreen;
- border-radius: 4px;
- filter: drop-shadow(2px 2px 6px black);
- position: relative;
- }
- .mama::before, .mama::after {
- position: absolute;
- content: '';
- }
- .mama::before {
- background: green;
- width: 0%;
- height: 100%;
- animation: var(--ani); /*charging 5s linear forwards;*/
- }
- .mama::after {
- background: darkgreen;
- width: 10px;
- height: 30px;
- top: 5px;
- right: -10px;
- }
- @keyframes charging {
- to { width: 100%; }
- }
- </style>
- <div class="mama"></div>
- <p><button id="btn" type="button" value="btn">马上充电</button></p>
- <script>
- let mama = document.querySelector('.mama');
- btn.onclick = () => {
- mama.style.setProperty('--ani','');
- setTimeout( () => {
- mama.style.setProperty('--ani','charging 5s linear forwards');
- }, 10);
- };
- </script>
复制代码
|
|