Created
July 22, 2012 16:48
-
-
Save yamitake/3160253 to your computer and use it in GitHub Desktop.
jquerty.glance.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function($) { | |
| $.fn.glance= function(options){ | |
| /** | |
| * default Options | |
| */ | |
| var defaults ={ | |
| texts : [[" |ω・`)チラッ" , 500 ] , | |
| ["┃ω・)ジー" , 1000 ], | |
| ["|)彡サッ" , 10000], | |
| ["" , 500] , | |
| ""] , | |
| waitTime: 1500 , | |
| delay:10000 , | |
| loop:3 | |
| }; | |
| var opts = $.extend(defaults , options); | |
| return this.each(function(){ | |
| var elem = $(this); | |
| var originalText = elem.text(); | |
| var index = 0; | |
| glance(elem , originalText , index , opts); | |
| }); | |
| }; | |
| function glance(elem , originalText , index , opts){ | |
| var waitTime = opts.waitTime; | |
| var text = opts.texts[index]; | |
| if(opts.texts[index] instanceof Array){ | |
| waitTime = text[1]; | |
| text = text[0]; | |
| } | |
| if(index == 0){ | |
| waitTime = opts.delay; | |
| } | |
| index++; | |
| setTimeout(function(){ | |
| elem.text(text + originalText); | |
| if(isFinished(index , opts)){ | |
| elem.text(originalText); | |
| if(--opts.loop > 0){ | |
| index = 0; | |
| setTimeout(function(){ | |
| glance(elem , originalText , index , opts); | |
| } , opts.delay); | |
| } | |
| }else{ | |
| glance(elem , originalText , index , opts); | |
| } | |
| } , waitTime); | |
| }; | |
| function isFinished(index , opts){ | |
| return (index >= opts.texts.length); | |
| } | |
| })(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment