-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathjquery.aim.min.js
2 lines (2 loc) · 2.88 KB
/
jquery.aim.min.js
1
2
jquery-aim 2014-08-13
!function(a){function b(b,c,d,e,f){var g=f;b.x&&b.y&&(c.x=.7*c.x+.3*(d-b.x),c.y=.7*c.y+.3*(e-b.y)),b.x=d,b.y=e,i=Math.sqrt(c.x*c.x+c.y*c.y),.1>i&&(c.x=0,c.y=0),g.effectiveSize=Math.sqrt(g.size*i+1),g.center.x=.7*g.center.x+.3*(b.x+c.x*k),g.center.x<0&&(g.center.x=0),g.center.x>a(window).width()-g.effectiveSize&&(g.center.x=a(window).width()-g.effectiveSize),g.rect.x0=g.center.x-g.effectiveSize,g.rect.x1=g.center.x+g.effectiveSize,g.center.y=.7*g.center.y+.3*(b.y+c.y*k),g.center.y<0&&(g.center.y=0),g.center.y>a(window).height()-g.effectiveSize&&(g.center.y=a(window).height()-g.effectiveSize),g.rect.y0=g.center.y-g.effectiveSize,g.rect.y1=g.center.y+g.effectiveSize}function c(a){{var b=a.outerWidth(),c=a.outerHeight(),d=a.offset().left,e=a.offset().top;Math.sqrt(b*b+c*c)}a.data("aim-data",{rect:{x0:d,y0:e,x1:d+b,y1:e+c},center:{x:d,y:e},increment:0})}function d(){var b=o.size,c=a("<div>").attr({id:"jquery-aim-debug"}).css({width:2*b+"px",height:2*b+"px","margin-left":-b+"px","margin-top":-b+"px",top:0,left:0,border:"2px solid #333",opacity:.3,"background-color":"yellowgreen",position:"absolute","pointer-events":"none"}).appendTo(a("body"));return c}function e(a,b){var c=Math.max(0,Math.min(a.x1,b.x1)-Math.max(a.x0,b.x0)),d=Math.max(0,Math.min(a.y1,b.y1)-Math.max(a.y0,b.y0));return c*d/(o.effectiveSize*o.effectiveSize)}function f(b){var d=a(this);a.inArray(d,g)>-1||(g.push(d),c(d),d.data("aim-data").options=b)}var g=[],h={x:0,y:0},i=0,j={x:0,y:0},k=12,l=0,m=0,n=!1,o={size:50,center:{x:0,y:0},effectiveSize:1};o.rect={x0:0,y0:0,x1:o.size,y1:o.size},a.fn.aim=function(a){return this.each(function(){f.call(this,a)}),this},a.aim={},a.aim.setDebug=function(b){if(b){if(a("#jquery-aim-debug").length)return;o.elem=d()}else a("#jquery-aim-debug").remove(),o.elem=null;n=b},a.aim.setAnticipateFunction=function(a){"function"==typeof a&&(b=a)},a().ready(function(){document.addEventListener("mousemove",function(a){l=a.clientX,m=a.clientY},!1)});setInterval(function(){var a=o;if(g.length){b(j,h,l,m,a);var c="translate("+a.center.x+"px,"+a.center.y+"px) scale("+a.effectiveSize/a.size+")";n&&a.elem.css({"-webkit-transform":c,"-moz-transform":c,"-ms-transform":c,transform:c});for(var d=0;d<g.length;d++){var f=g[d],k=f.data("aim-data"),p=e(k.rect,a.rect);if(p&&0!==i){k.increment=k.increment+.2*p,k.increment>1&&k.increment<2?(k.options.className?f.addClass(k.options.className):k.options.aimEnter&&"function"==typeof k.options.aimEnter&&k.options.aimEnter.call(f,!0),k.increment>2&&(k.increment=2),n&&a.elem.css("background-color","tomato")):k.increment>2&&(k.increment=2,n&&a.elem.css("background-color","tomato"));break}n&&a.elem.css("background-color","yellowgreen"),0!==k.increment&&(k.increment=k.increment-.05,k.increment<0&&(k.increment=0,k.options.className?f.removeClass(k.options.className):k.options.aimExit&&"function"==typeof k.options.aimExit&&k.options.aimExit.call(f,!0)))}}},16)}(jQuery);