博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Jquery插件 自制进度条
阅读量:4574 次
发布时间:2019-06-08

本文共 2422 字,大约阅读时间需要 8 分钟。

  HTML

1     
2
3
4
5
6
0%
7

CSS

1         .progress { 2             position: relative; 3             width: 300px; 4             margin: 100px auto; 5         } 6  7         .progress_bg { 8             height: 10px; 9             border: 1px solid #ddd;10             border-radius: 5px;11             overflow: hidden;12             background-color: #f2f2f2;13         }14 15         .progress_bar {16             background: #5FB878;17             width: 0;18             height: 10px;19             border-radius: 5px;20         }21 22         .progress_btn {23             width: 20px;24             height: 20px;25             border-radius: 5px;26             position: absolute;27             background: #fff;28             left: 0px;29             margin-left: -10px;30             top: -5px;31             cursor: pointer;32             border: 1px #ddd solid;33             box-sizing: border-box;34         }35 36             .progress_btn:hover {37                 border-color: #F7B824;38             }

JQUERY

1 $(function () { 2     var tag = false, ox = 0, left = 0, bgleft = 0; 3     $('.progress_btn').mousedown(function (e) { 4         ox = e.pageX - left; 5         tag = true; 6     }); 7     $(document).mouseup(function () { 8         tag = false; 9     });10     $('.progress').mousemove(function (e) {
//鼠标移动11 if (tag) {12 left = e.pageX - ox;13 if (left <= 0) {14 left = 0;15 } else if (left > 300) {16 left = 300;17 }18 $('.progress_btn').css('left', left);19 $('.progress_bar').width(left);20 $('.text').html(parseInt((left / 300) * 100) + '%');21 }22 });23 $('.progress_bg').click(function (e) {
//鼠标点击24 if (!tag) {25 bgleft = $('.progress_bg').offset().left;26 left = e.pageX - bgleft;27 if (left <= 0) {28 left = 0;29 } else if (left > 300) {30 left = 300;31 }32 $('.progress_btn').css('left', left);33 $('.progress_bar').animate({ width: left }, 300);34 $('.text').html(parseInt((left / 300) * 100) + '%');35 }36 });37 });

 

转载于:https://www.cnblogs.com/CoffeeEddy/p/7448344.html

你可能感兴趣的文章
省市县三级联动
查看>>
多IP地址--笔记
查看>>
react native开发日记
查看>>
Virtual Dom是什么
查看>>
阶乘之和
查看>>
Unable to instantiate receiver xxx.receiver.NetworkReceiver异常
查看>>
C++调用C#类库函数
查看>>
vs2013编译项目去掉warning信息
查看>>
ASP.NET MVC html help
查看>>
C# 时间比较方法DateTime.Compare
查看>>
三级菜单小练习
查看>>
vim 插件管理
查看>>
Guid函数
查看>>
java的加减乘除问题
查看>>
Android 系统常用的权限
查看>>
类型参数约束 : Controller where T : class,new()
查看>>
N卡控制面板把physx设置为cpu
查看>>
Javsssist用InsertAt()方法对语句插桩
查看>>
java安装Jboss插件
查看>>
宝塔apache配置
查看>>