• Just add this code to animated-typing-effect/assets/js/typed.fe.js

    (function( $ ) {
      $.fn.isOnScreen = function() {
    	var win = $(window);
    	var viewport = {
    		top: win.scrollTop(),
    		left: win.scrollLeft()
    	};
    	viewport.right = viewport.left + win.width();
    	viewport.bottom = viewport.top + win.height();
    	var bounds = this.offset();
    	bounds.right = bounds.left + this.outerWidth();
    	bounds.bottom = bounds.top + this.outerHeight();
    	return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom));
    }; 
    	
      $(window).on('resize scroll', function() {
        $( '.typed-me' ).each( function() {
          var options = {}, strings = [];
          for( var key in this.dataset ) {
            if( key.substr( 0, 6 ) == "string" ) {
              var v = this.dataset[ key ].replace( /&quot;/g, '"' );
              // Replace & with & otherwise the browser freezes.
              v = v.replace(/"/g, '&quot;');
              v = v.replace('&', '&'); // in case the user already used &
              v = v.replace('&', '&');
    
              strings.push( v );
            } else {
              options[ key ] = parseInt( this.dataset[ key ] );
            }
          }
    
          options[ 'strings' ] = strings;
          options[ 'contentType' ] = 'html';
    		if ($( '.typed-me' ).isOnScreen()) {
          		$( this ).typed( options );
    		}
        });
      });
    })(jQuery);
  • The topic ‘Anyone who want to show only if viewport is visible’ is closed to new replies.