-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathjquery.funnyText.min.js
14 lines (14 loc) · 3.44 KB
/
jquery.funnyText.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/**
* funnyText.js 0.4 Beta
* https://github.com/alvarotrigo/funnyText.js
* MIT licensed
*
* Copyright (C) 2013 alvarotrigo.com - A project by Alvaro Trigo
*/
(function(b){function t(){var e=(document.body||document.documentElement).style,b="transition";if("string"==typeof e[b])return!0;v="Moz Webkit Khtml O ms Icab".split(" ");for(var b=b.charAt(0).toUpperCase()+b.substr(1),k=0;k<v.length;k++)if("string"==typeof e[v[k]+b])return!0;return!1}b.fn.funnyText=function(e){function h(a,d){return a+Math.floor(Math.random()*(d+1))}function k(a,d){var c;h(0,100)%2&&"both"==e.direction||"horizontal"==e.direction?"right"==a&&"top"==d?c="left top moveLeft":"right"==
a&&"bottom"==d?c="left bottom moveLeft":"left"==a&&"top"==d?c="right top moveRight":"left"==a&&"bottom"==d&&(c="right bottom moveRight"):"right"==a&&"top"==d?c="right bottom moveDown":"right"==a&&"bottom"==d?c="right top moveUp":"left"==a&&"top"==d?c="left bottom moveDown":"left"==a&&"bottom"==d&&(c="left top moveUp");return c}function u(a,d){setTimeout(function(){q(a)},d*e.speed)}function q(a){var d=a.outerHeight()/2,c=a.outerWidth()/2,b=a.find(".active");t()?b.hasClass("moveRight")?a.hasClass("moved")?
a.css("left","0px"):a.css("left","-"+c+"px"):b.hasClass("moveLeft")?a.hasClass("moved")?a.css("left","-"+c+"px"):a.css("left","0px"):b.hasClass("moveUp")?a.hasClass("moved")?a.css("top","-"+d+"px"):a.css("top","0px"):b.hasClass("moveDown")&&(a.hasClass("moved")?a.css("top","0px"):a.css("top","-"+d+"px")):b.hasClass("moveRight")?a.hasClass("moved")?a.animate({left:"0px"},400):a.animate({left:"-"+c+"px"},400):b.hasClass("moveLeft")?a.hasClass("moved")?a.animate({left:"-"+c+"px"},400):a.animate({left:"0px"},
400):b.hasClass("moveUp")?a.hasClass("moved")?a.animate({top:"-"+d+"px"},400):a.animate({top:"0px"},400):b.hasClass("moveDown")&&(a.hasClass("moved")?a.animate({bottom:"0px"},400):a.animate({bottom:d+"px"},400));a.toggleClass("moved")}e=b.extend({speed:700,borderColor:"black",activeColor:"white",color:"black",fontSize:"7em",direction:"both"},e);var l=b(this);l.addClass("funnyText");var n=b(this),f=b.trim(n.text()).split(""),w=["top","bottom"],x=["left","right"],m,p,r;n.html("");m=b("<style>"+l.selector+
".funnyText span.active { color: "+e.activeColor+"; text-shadow: -1px 0 "+e.borderColor+", 0 1px "+e.borderColor+", 1px 0 "+e.borderColor+", 0 -1px "+e.borderColor+";} "+l.selector+".funnyText span{color: "+e.color+"; font-size:"+e.fontSize+";}</style>");b("html > head").append(m);for(var g=0;g<f.length;g++){p=w[h(0,100)%2];m=x[h(0,100)%2];" "==f[g]&&(f[g]=" ");var y='<span class="normal '+p+" "+m+'">'+f[g]+"</span>";do activePositionXY=k(m,p);while(activePositionXY==r&&"both"==e.direction);
r=activePositionXY;n.append('<div class="charWrap">'+y+('<span class="active '+activePositionXY+'">'+f[g]+"</span>")+"</div>")}l.find(".charWrap").each(function(){var a=b(this).find("span").outerWidth(),d=b(this).find("span").outerHeight();b(this).css({width:2*a+"px",height:2*d+"px"});var c=b(this);c.find(".normal").hasClass("bottom")?c.css("top","-"+c.find(".normal").outerHeight()+"px"):c.css("top","0px");c.find(".normal").hasClass("right")?c.css("left","-"+c.find(".normal").outerWidth()+"px"):c.css("left",
"0px");b(this).wrap('<div class="character" style="width:'+a+"px; height: "+d+'px"></div>')});setInterval(function(){var a=h(2,6);do var b=h(0,f.length-1);while(""===b);u(l.find(".charWrap").eq(b),a)},1*e.speed);b(".charWrap").hover(function(){b(this).hasClass("moved")||q(b(this))})}})(jQuery);