Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery( document ).ready( function() {
- $target = '.no-thumbnail';
- manipulateCircleText( $target );
- });
- /*
- * This function sets up the HTML of the circles ready for CSS to
- * manipulate the text so that the first letter shows by default
- * and only on-hover the rest of the text shows
- */
- function manipulateCircleText( $target ) {
- $ = jQuery;
- // For each circle
- $( 'article.post' ).each(function() {
- // Start off by wrapping a <span> around all other characters other than the first one
- // So that you can style those other characters (hide them off screen) with CSS
- wrapSpan( this, $target );
- // On-hover of the circle
- $( this ).find( 'a' ).hover(
- // Hover-in
- function() {
- // Delete the span tag we've wrapped to the circle title
- deleteSpan( this, $target );
- },
- // Hover-out
- function() {
- // Return the <span> back to all the characters but the first
- wrapSpan( this, $target );
- }
- );
- // Do the same on-focus (for keyboard users) of the circle
- $( this ).find( 'a' ).focus(
- // Focus-in
- function() {
- // Delete the span tag we've wrapped to the circle title
- deleteSpan( this, $target );
- }
- )
- // Focus-out
- .blur( function() {
- // Return the <span> back to all the characters but the first
- wrapSpan( this, $target );
- });
- });
- /*
- * Wrap all but the first character with a span
- */
- function wrapSpan( $this ) {
- $title = $( $this ).find( $target );
- $countTitleChars = $title.text().length;
- $firstChar = $( $title ).text().substr( 0, 1 );
- $otherChars = $( $title ).text().substr( 1, $countTitleChars );
- $( $this ).find( $target ).empty().html( '<span>' + $firstChar + '</span>' + '<span class="otherChars">' + $otherChars + '</span>' );
- }
- /*
- * Delete the span we've wrapped
- */
- function deleteSpan( $this, $target ) {
- // Get the words of the title
- $titleWords = $( $this ).find( $target ).text();
- // Get rid of the <span> we just added by erasing the title
- $( $this ).children( 'span' ).empty()
- // Then add the original title back in, clean of our modifications.
- .text( $titleWords );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement