• 技术文章 >web前端 >html教程

    滑动条效果_html/css_WEB-ITnose

    2016-06-24 11:46:24原创623

    准备将自己做的滑动条效果都放在这篇博文下。

    自己的第一个成果

    css

    body{        background: black;    }    #slider_1{        width: 400px;        height: 2px;        border-radius: 1px;        display: -webkit-flex;        position: relative;        margin: 30px auto;    }        #oSlider{        width: 15px;        height: 15px;        position: absolute;        border: 1px solid rgb(249,247,107);        border-radius: 10px;        background: rgb(249,247,107);        top: -7px;    }    #slider_11{        -webkit-flex:1;        background: rgb(249,247,107);        border-radius: 1px 0 0 1px;    }    #slider_12{        -webkit-flex:1;        background: rgba(255,255,255,0.3);        border-radius: 0 1px 1px 0px;    }  

       #num{
          font-size: 24px;
          color: white;
          display: block;
          text-align: center;
        }

     

    html

    js

    var slider_1=document.getElementById("slider_1");
    var oSlider=document.getElementById("oSlider");
    var num=document.getElementById("num");
    var width=400;
    var min=-7;
    var max=393;
    var drag=false;
    var slider_11=document.getElementById("slider_11");
    var slider_12=document.getElementById("slider_12");
    slider_1.onclick=function(){
    var ewidth=event.clientX-slider_1.offsetLeft;
    change(ewidth);

    }
    oSlider.onmousedown=function(){
    drag=true;
    }
    document.onmousemove=function(){
    if(drag){
    var ewidth=event.clientX-slider_1.offsetLeft;
    if(ewidth<=min||ewidth>=max) return ;
    change(ewidth);
    }
    }
    document.onmouseup=function(){
    drag=false;
    }
    function change(ewidth){
    num.innerText=Math.round((ewidth+6)/width*100);
    slider_11.style["-webkit-flex"]=ewidth/width;
    slider_12.style["-webkit-flex"]=(width-ewidth)/width;
    oSlider.style.left=ewidth+"px";
    }

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:滑动条效果
    上一篇:CSS3的[att^=val]选择器_html/css_WEB-ITnose 下一篇:自己动手写 PHP MVC 框架(40节精讲/巨细/新人进阶必看)

    相关文章推荐

    • 免费下载:简单、优雅的现代风格界面工具包_html/css_WEB-ITnose• 开始的续写_html/css_WEB-ITnose• html +CSS+div学习――第二课_html/css_WEB-ITnose• 有关浏览器兼容样式问题_html/css_WEB-ITnose• 作为内联样式,在火狐和IE6显示正常;作为外联样式,火狐正常,IE6就是没有引入CSS的HTML内容。_html/css_WEB-ITnose
    1/1

    PHP中文网