Skip to content

Instantly share code, notes, and snippets.

@salipro4ever
Created April 29, 2016 02:48
Show Gist options
  • Save salipro4ever/8455c9798eacee40878e5780c156d3be to your computer and use it in GitHub Desktop.
Save salipro4ever/8455c9798eacee40878e5780c156d3be to your computer and use it in GitHub Desktop.
typingEffect
function loadNewsInteresting(){
typingEffect($('.index_news_interesting_lst').children('li.activated').children('a'),1);
}
function typingEffect(obj, opt){
var str = obj.text();
var allChar = str.length;
var count = 0;
var intervalTyping = null;
obj.html('').show();
if(opt == 1){
intervalTyping = setInterval(function(){
if(count <= allChar)
obj.text(str.substring(0, count++));
else{
clearInterval(intervalTyping);
setTimeout(function(){typingEffect(obj,0);},2000);
}
},50);
}
else{
count = allChar - 1;
intervalTyping = setInterval(function(){
if(count >= 0)
obj.text(str.substring(0, count--));
else {
obj.text(str).hide();
clearInterval(intervalTyping);
var next_lst = null;
if (jQuery('.index_news_interesting_lst').children('li.activated').next().length > 0) {
next_lst = $('.index_news_interesting_lst').children('li.activated').next();
}else{
next_lst = $('.index_news_interesting_lst').children('li:first-child');
}
$('.index_news_interesting_lst').children('li.activated').removeClass('activated');
next_lst.addClass('activated');
loadNewsInteresting();
}
},20);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment