Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Animation in separate function. #2

Merged
merged 2 commits into from

2 participants

@sudodoki

When updating input value, slider changes its state without animation.

@sudodoki

Wasn't sure about minifying, so used this http://compressorrater.thruhere.net/ and chose the shortest version.

@nikorablin nikorablin merged commit d69ad0d into nikorablin:master
@nikorablin
Owner

Looks good, didn't think about putting the animation in a separate function, works well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 6 deletions.
  1. +4 −5 jquery.slideControl.js
  2. +1 −1  jquery.slideControl.min.js
View
9 jquery.slideControl.js
@@ -38,6 +38,7 @@
var containerWidth = container.outerWidth() + 1;
var handleWidth = $(handle).outerWidth();
var offset = $(container).offset();
+ var animate = function(value){$(fill).animate({ width: value + "%"}, o.speed);}
$(window).resize(function() {
offset = $(container).offset();
@@ -53,9 +54,7 @@
e.preventDefault();
position = checkBoundaries(Math.round(((e.pageX - offset.left + handleWidth/2)/containerWidth)*100));
- $(fill).animate({
- width: position + "%"
- }, o.speed);
+ animate(position);
$(input).val(position/10);
});
@@ -84,7 +83,7 @@
$(input).val(o.upperBound);
else if ($(this).val() < o.lowerBound)
$(input).val(o.lowerBound);
- $(fill).width(value + "%");
+ animate(value);
});
});
@@ -112,4 +111,4 @@
}
return this;
}
-})(jQuery);
+})(jQuery);
View
2  jquery.slideControl.min.js
@@ -1 +1 @@
-(function(a){a.fn.slideControl=function(b){function d(a){if(a<b.lowerBound*10)return b.lowerBound*10;else if(a>b.upperBound*10)return b.upperBound*10;else return a}function e(){var a=-1;if(navigator.appName=="Microsoft Internet Explorer"){var b=navigator.userAgent;var c=new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})");if(c.exec(b)!=null)a=parseFloat(RegExp.$1)}return a}var c={speed:400,lowerBound:1,upperBound:10};var b=a.extend(c,b);return this.each(function(){var c=b;var f=false;var g=0;var h=this;a(this).addClass("slideControlInput");var i=a(this).parent();var j=a(i).find("label");i.html("<label>"+a(j).html()+'</label><span class="slideControlContainer"><span class="slideControlFill" style="width:'+a(h).val()*10+'%"><span class="slideControlHandle"></span></span></span>'+a(h).wrap("<span></span>").parent().html());var k=i.find(".slideControlContainer");var l=k.find(".slideControlFill");var m=l.find(".slideControlHandle");var n=i.find("input");var o=k.outerWidth()+1;var p=a(m).outerWidth();var q=a(k).offset();a(window).resize(function(){q=a(k).offset()});if(e()<9&&e()>-1){m.addClass("ieShadow")}a(k).click(function(b){b.preventDefault();g=d(Math.round((b.pageX-q.left+p/2)/o*100));a(l).animate({width:g+"%"},c.speed);a(n).val(g/10)});a(m).mousedown(function(b){b.preventDefault();f=true;a(document).mousemove(function(b){b.preventDefault();g=d(Math.round((b.pageX-q.left+p/2)/o*100));if(f){a(l).width(g+"%");a(n).val(g/10)}});a(document).mouseup(function(){b.preventDefault();f=false})});a(n).change(function(){var b=d(a(this).val()*10);if(a(this).val()>c.upperBound)a(n).val(c.upperBound);else if(a(this).val()<c.lowerBound)a(n).val(c.lowerBound);a(l).width(b+"%")})});return this}})(jQuery)
+(function(a){a.fn.slideControl=function(c){var t={speed:400,lowerBound:1,upperBound:10};var c=a.extend(t,c);return this.each(function(){var d=c;var j=false;var e=0;var o=this;a(this).addClass('slideControlInput');var h=a(this).parent();var u=a(h).find('label');h.html(""+a(u).html()+""+a(o).wrap("").parent().html());var f=h.find('.slideControlContainer');var k=f.find('.slideControlFill');var l=k.find('.slideControlHandle');var g=h.find('input');var p=f.outerWidth()+1;var q=a(l).outerWidth();var m=a(f).offset();var r=function(b){a(k).animate({width:b+"%"},d.speed)}a(window).resize(function(){m=a(f).offset()})if(s()<9&&s()>-1){l.addClass('ieShadow')}a(f).click(function(b){b.preventDefault();e=n(Math.round(((b.pageX-m.left+q/2)/p)*100));r(e);a(g).val(e/10)});a(l).mousedown(function(i){i.preventDefault();j=true;a(document).mousemove(function(b){b.preventDefault();e=n(Math.round(((b.pageX-m.left+q/2)/p)*100));if(j){a(k).width(e+"%");a(g).val(e/10)}});a(document).mouseup(function(){i.preventDefault();j=false})});a(g).change(function(){var b=n(a(this).val()*10);if(a(this).val()>d.upperBound)a(g).val(d.upperBound);else if(a(this).val()c.upperBound*10)return c.upperBound*10;else return b}function s(){var b=-1;if(navigator.appName=='Microsoft Internet Explorer'){var i=navigator.userAgent;var d=new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");if(d.exec(i)!=null)b=parseFloat(RegExp.$1)}return b}return this}})(jQuery);
Something went wrong with that request. Please try again.