Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function($){
- $(function(){
- "use strict";
- // see it in action on codepen: https://codepen.io/anon/pen/ryedMR
- var crazyAnimation =
- {
- init : function()
- {
- this.vars();
- this.events();
- },
- vars : function()
- {
- this.header = $('#changing-title');
- this.crazy = $( 'div.crazy.video');
- this.default = 'Default Text';
- },
- phrases : [
- "word 1",
- "word 2",
- "word 3",
- "word 4", // etc.
- ],
- iterate : function( el, i = 0, $this = this )
- {
- if ( i < this.phrases.length )
- {
- setTimeout(function()
- {
- if ( $this.crazy.hasClass( 'show' ) )
- {
- el.text( $this.phrases[i] );
- i === $this.phrases.length - 1 ? i = 0 : i++;
- $this.iterate( el, i );
- }
- }, 200, el );
- }
- },
- events : function( $this = this )
- {
- this.header.on(
- {
- mouseenter : function()
- {
- $this.crazy.addClass( 'show' );
- $this.iterate( $(this).children( 'span' ) );
- },
- mouseleave : function()
- {
- $this.crazy.removeClass( 'show' );
- $(this).children( 'span' ).text( $this.default );
- },
- });
- }
- }.init();
- });
- }(jQuery));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement