bar.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. var scale = function (btn,bar,title,numtitle){
  2. this.btn=document.getElementById(btn);
  3. this.bar=document.getElementById(bar);
  4. this.title=document.getElementById(title);
  5. this.numtitle=numtitle;
  6. this.step=this.bar.getElementsByTagName("div")[0];
  7. this.init();
  8. };
  9. scale.prototype={
  10. init:function (){
  11. var f=this,g=document,b=window,m=Math;
  12. f.btn.onmousedown=function (e){
  13. var x=(e||b.event).clientX;
  14. var l=this.offsetLeft;
  15. var max=f.bar.offsetWidth-this.offsetWidth;
  16. g.onmousemove=function (e){
  17. var thisX=(e||b.event).clientX;
  18. var to=m.min(max,m.max(-2,l+(thisX-x)));
  19. f.btn.style.left=to+'px';
  20. f.ondrag(m.round(m.max(0,to/max)*100),to);
  21. b.getSelection ? b.getSelection().removeAllRanges() : g.selection.empty();
  22. };
  23. g.onmouseup=new Function('this.onmousemove=null');
  24. };
  25. },
  26. ondrag:function (pos,x){
  27. this.step.style.width=Math.max(0,x)+'px';
  28. this.title.innerHTML=pos+'%';
  29. if(this.numtitle=='numtitle'){
  30. changenum();
  31. }else{
  32. changenum2();
  33. }
  34. }
  35. }
  36. new scale('btn','bar','title','numtitle');
  37. new scale('btn2','bar2','title2','numtitle2');