zoukankan      html  css  js  c++  java
  • 简单的javascript/css slider滑动条

    
    


    <!
    DOCTYPE html> <html> <head> <style type="text/css"> #bar{ width:200px; height:25px; border:1px solid black; position:relative; } #slider{ width:0%; height:100%; background-color:red; top:0px; left:0px; position:absolute; cursor:pointer; } #info{ width:200px; height:25px; border:1px solid black; } </style> <script type="text/javascript"> var bar, slider; function init(){ bar = document.getElementById('bar'); slider = document.getElementById('slider'); info = document.getElementById('info'); bar.addEventListener('mousedown', startSlide, false); bar.addEventListener('mouseup', stopSlide, false); } function startSlide(event){ var set_perc = ((((event.clientX - bar.offsetLeft) / bar.offsetWidth)).toFixed(2)); info.innerHTML = 'start' + set_perc + '%'; bar.addEventListener('mousemove', moveSlide, false); slider.style.width = (set_perc * 100) + '%'; } function moveSlide(event){ var set_perc = ((((event.clientX - bar.offsetLeft) / bar.offsetWidth)).toFixed(2)); info.innerHTML = 'moving : ' + set_perc + '%'; slider.style.width = (set_perc * 100) + '%'; } function stopSlide(event){ var set_perc = ((((event.clientX - bar.offsetLeft) / bar.offsetWidth)).toFixed(2)); info.innerHTML = 'done : ' + set_perc + '%'; bar.removeEventListener('mousemove', moveSlide, false); slider.style.width = (set_perc * 100) + '%'; } </script> </head> <body onload='init()'> <div id='bar'> <div id='slider'> </div> </div> <br /> <div id='info'>info</div> </body> </html>
  • 相关阅读:
    你应该掌握的七种回归技术
    jar包运行
    Spark常见问题汇总,spark相关错误和解决方法,,,,,,,,,
    shell把字符串中的字母去掉,只保留数字
    excel求和结果不对
    Matlab实现PCA
    Spring3.0 AOP 具体解释
    POJ 1422 Air Raid(二分图匹配最小路径覆盖)
    TCP、UDP和HTTP
    2014世界互联网乌镇峰会 马云演讲实录
  • 原文地址:https://www.cnblogs.com/wwwggg/p/2746901.html
Copyright © 2011-2022 走看看