slider.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. if((/ Chrome\/([\.0-9]+)/).exec(navigator.userAgent)){
  2. $.fn.slider = function(cfg){
  3. this.sliderCfg = {
  4. min: cfg && !isNaN(parseFloat(cfg.min)) ? Number(cfg.min) : null,
  5. max: cfg && !isNaN(parseFloat(cfg.max)) ? Number(cfg.max) : null,
  6. step: cfg && Number(cfg.step) ? cfg.step : 1,
  7. callback: cfg && cfg.callback ? cfg.callback : null
  8. };
  9. var $input = $(this);
  10. var min = this.sliderCfg.min;
  11. var max = this.sliderCfg.max;
  12. var step = this.sliderCfg.step;
  13. var callback = this.sliderCfg.callback;
  14. /*$input.attr('min', min)
  15. .attr('max', max)
  16. .attr('step', step);*/
  17. $input.bind("input", function(e){
  18. $(this).attr('value', this.value);
  19. var min = $(this).attr('min');
  20. var max = $(this).attr('max');
  21. var percent = this.value / max*100;
  22. $(this).css( 'background', 'linear-gradient(to right, #059CFA, white ' + percent + '%, white)' );
  23. if ($.isFunction(callback)) {
  24. callback(this);
  25. }
  26. });
  27. };
  28. $(document).ready(function(){
  29. $('input[type="range"]').slider();
  30. });
  31. }