• Jquery实现可拖动进度条


    html

     
        <div class="progress">
                <div class="progress_bg">
                    <div class="progress_bar"></div>
                </div>
                <div class="progress_btn"></div>
                <div class="text">0%</div>
            </div>
     

    css

     
         .progress{position: relative; 300px;margin:100px auto;}
            .progress_bg{height: 10px; border: 1px solid #ddd; border-radius: 5px; overflow: hidden;background-color:#f2f2f2;}
            .progress_bar{background: #5FB878;  0; height: 10px; border-radius: 5px;}
            .progress_btn{ 20px; height: 20px; border-radius: 5px; position: absolute;background:#fff; 
            left: 0px; margin-left: -10px; top:-5px; cursor: pointer;border:1px #ddd solid;box-sizing:border-box;}
            .progress_btn:hover{border-color:#F7B824;}
     

    js

     
        $(function(){
                    var tag = false,ox = 0,left = 0,bgleft = 0;
                    $('.progress_btn').mousedown(function(e) {
                        ox = e.pageX - left;
                        tag = true;
                    });
                    $(document).mouseup(function() {
                        tag = false;
                    });
                    $('.progress').mousemove(function(e) {//鼠标移动
                        if (tag) {
                            left = e.pageX - ox;
                            if (left <= 0) {
                                left = 0;
                            }else if (left > 300) {
                                left = 300;
                            }
                            $('.progress_btn').css('left', left);
                            $('.progress_bar').width(left);
                            $('.text').html(parseInt((left/300)*100) + '%');
                        }
                    });
                    $('.progress_bg').click(function(e) {//鼠标点击
                        if (!tag) {
                            bgleft = $('.progress_bg').offset().left;
                            left = e.pageX - bgleft;
                            if (left <= 0) {
                                left = 0;
                            }else if (left > 300) {
                                left = 300;
                            }
                            $('.progress_btn').css('left', left);
                            $('.progress_bar').animate({left},300);
                            $('.text').html(parseInt((left/300)*100) + '%');
                        }
                    });
                });
    效果图:
     
  • 相关阅读:
    html5--4-1 video/视频播放
    html5--3.22 综合实例03
    html5--3.21 课程小结与其他新增元素
    html5--3.20 新增的keygen元素
    UVA11324-- The Largest Clique(SCC+DP)
    memset函数具体说明
    XMPP协议的原理介绍
    探索WebKit内核(一)------ 菜鸟起步
    图像切割之(一)概述
    LeetCode——Count and Say
  • 原文地址:https://www.cnblogs.com/li-123/p/7132062.html
Copyright © 2020-2023  润新知