-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbordercoloranimate.min.js
10 lines (10 loc) · 1.52 KB
/
bordercoloranimate.min.js
1
2
3
4
5
6
7
8
9
10
/*!-----------------------------------------------------
* BorderColorAnimate v1.0.1
* (c) 2017 by Azat Ahmedov ([email protected])
* MIT License
* https://github.com/payalord/BorderColorAnimate
* hexToRgb by Tim Down: http://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb/5624139#5624139
* requestAnimFrame by Paul Irish: https://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
* and little bit extended by me
*------------------------------------------------------*/
;window.requestAnimFrame=(function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){window.setTimeout(a,20)}})();function hexToRgb(c){var b=/^#?([a-f\d])([a-f\d])([a-f\d])$/i;c=c.replace(b,function(e,h,f,d){return h+h+f+f+d+d});var a=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(c);return a?[parseInt(a[1],16),parseInt(a[2],16),parseInt(a[3],16)]:null}jQuery.fn.BorderColorAnimate=function(j,m,h){var m=m=="fast"?200:m=="slow"?600:typeof m=="undefined"?400:m;var l=jQuery(this);var k=l.css("border-color");var e=dRGB=step=[];e=k.match(/\d+/g);dRGB=hexToRgb(j);for(var b=0;b<3;b++){e[b]=+e[b];dRGB[b]=+dRGB[b];step[b]=(dRGB[b]-e[b])/m}var a=Date.now();function g(){var d=Date.now()-a;if(d>m){d=m}var c="rgb("+Math.ceil(e[0]+step[0]*d)+","+Math.ceil(e[1]+step[1]*d)+","+Math.ceil(e[2]+step[2]*d)+")";l.css("border-color",c);if(d<m){requestAnimFrame(g)}else{if(typeof h=="function"){l.f=h;l.f()}}}g();return l};