Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $YECBGYFECGEAFWHA as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2

Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $BBWFDDBHHYHDXXAB as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2
css+js如何实现简单的动态进度条效果?(代码实例)_创想鸟

css+js如何实现简单的动态进度条效果?(代码实例)

css+js如何实现简单的动态进度条?本篇文章就给大家用css+js制作一个简单的动态进度条效果,并将页面动态进度条滚动加载的代码分享给大家,感兴趣的小伙伴可以参考借鉴一下,希望对你们有所帮助。

我们要知道,这里主要使用了css3的animation动画属性,首先将进度条设置为一个初始宽度为0,背景色为绿色,高度与容器相同的元素;在通过animation动画属性对其宽度进行过渡,从而实现进度条填充的效果。

我们来看看css3的animation动画属性的相关知识。

animation 属性是一个简写属性,用于设置六个动画属性:

animation-name:规定需要绑定到选择器的 keyframe 名称;

立即学习“前端免费学习笔记(深入)”;

animation-duration:规定完成动画所花费的时间,以秒或毫秒计;

animation-timing-function:规定动画的速度曲线;

animation-delay:规定在动画开始之前的延迟;

animation-iteration-count:规定动画应该播放的次数;

animation-direction:规定是否应该轮流反向播放动画

下面我们来看看具体的实现动态进度条效果的方法。

css+js实现简单的动态进度条效果的代码示例:

html代码:

css代码:

#wrapper{    position: relative;    width:200px;    height:100px;    border:1px solid darkgray;}#progressbar{    position: absolute;    top:50%;    left:50%;    margin-left:-90px;    margin-top:-10px;    width:180px;    height:20px;    border:1px solid darkgray;}/*在进度条元素上调用动画*/#fill{    animation: move 2s;    text-align: center;    background-color: #6caf00;}/*实现元素宽度的过渡动画效果*/@keyframes move {    0%{        width:0;    }    100%{        width:100%;    }}

js代码:

var progressbar={    init:function(){        var fill=document.getElementById('fill');        var count=0;    //通过间隔定时器实现百分比文字效果,通过计算CSS动画持续时间进行间隔设置        var timer=setInterval(function(e){            count++;            fill.innerHTML=count+'%';            if(count===100) clearInterval(timer);        },17);    }};progressbar.init();

效果图:

1.gif

总结:以上就是本篇文章所介绍的css+js实现简单的动态进度条效果的全部内容,大家可以自己动手试试,加深理解,制作不同的进度条效果,希望能对大家的学习有所帮助。

相关推荐:

html5如何实现简单进度条效果?动态进度条的实现

css中clip属性是什么?clip:rect()制作圆形进度条动画

js实现自定义拖动进度条效果

以上就是css+js如何实现简单的动态进度条效果?(代码实例)的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1612926.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2025年12月24日 03:18:07
图文详解HTML和CSS怎么制作分页效果
下一篇 2025年12月24日 03:18:15

相关推荐

发表回复

登录后才能评论
关注微信