Skip to content

Instantly share code, notes, and snippets.

@my8bit
Forked from awildeone/index.html
Last active August 6, 2017 08:09
Show Gist options
  • Save my8bit/29c024123b065c90f93093947f6e1793 to your computer and use it in GitHub Desktop.
Save my8bit/29c024123b065c90f93093947f6e1793 to your computer and use it in GitHub Desktop.
jQuery Text Rotator
<h1> I am
<div id="rotate">
<div>awesome.</div>
<div>invincible.</div>
<div>unbeatable.</div>
<div>indestructible.</div>
</div>
</h1>
$(document).ready(function() {
$('#rotate').rotaterator({fadeSpeed:200, pauseSpeed:7500});
});
(function($){
$.fn.extend({
rotaterator: function(options) {
var defaults = {
fadeSpeed: 100,
pauseSpeed: 1000
,
child:null
};
var options = $.extend(defaults, options);
return this.each(function() {
var o =options;
var obj = $(this);
var items = $(obj.children(), obj);
items.each(function() {$(this).hide();})
if(!o.child){var next = $(obj).children(':first');
}else{var next = o.child;
}
$(next).fadeIn(o.fadeSpeed, function() {
$(next).delay(o.pauseSpeed).fadeOut(o.fadeSpeed, function() {
var next = $(this).next();
if (next.length == 0){
next = $(obj).children(':first');
}
$(obj).rotaterator({child : next, fadeSpeed : o.fadeSpeed, pauseSpeed : o.pauseSpeed});
})
});
});
}
});
})(jQuery);
!function(e){e.fn.extend({rotaterator:function(d){var t={fadeSpeed:100,pauseSpeed:1e3,child:null},d=e.extend(t,d);return this.each(function(){var t=d,n=e(this);if(e(n.children(),n).each(function(){e(this).hide()}),t.child)a=t.child;else var a=e(n).children(":first");e(a).fadeIn(t.fadeSpeed,function(){e(a).delay(t.pauseSpeed).fadeOut(t.fadeSpeed,function(){var d=e(this).next();0==d.length&&(d=e(n).children(":first")),e(n).rotaterator({child:d,fadeSpeed:t.fadeSpeed,pauseSpeed:t.pauseSpeed})})})})}})}(jQuery);
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment