Skip to content

Instantly share code, notes, and snippets.

@yamitake
Created July 22, 2012 16:48
Show Gist options
  • Select an option

  • Save yamitake/3160253 to your computer and use it in GitHub Desktop.

Select an option

Save yamitake/3160253 to your computer and use it in GitHub Desktop.
jquerty.glance.js
(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