Question

I have a class I named '.social' that I have open up once the div is clicked. Inside is a switch case statement so that once it is clicked, if you click it again, the div closes back up. I am only showing one letter within it, using the 'overflow' and letter spacing attributes to hide the rest of the letters. Once the div is clicked, I want to expand the div, and decrease the letter spacing together, so that all of the word is displayed.

jQuery:

$(document).ready(function () {
var SocialClick = true;

$('.social').mousedown(function () {
    switch (SocialClick) {
        case true:
            $('.social h1').css({'letter-spacing': 'none'}, 1000);
            $(this).stop().animate({ width: '150px' }, 500);
            SocialClick = false;
            break;
        case false:
            $(this).stop().animate({ width: '50px' }, 500);
            SocialClick = true;
            break;
        }
    });
});

CSS:

.social {
    overflow: hidden;
    z-index: 50;
    display: block;
    float: right;
    margin-top: -52px;
    margin-right: 50px;
    width: 50px;
    height: 50px;
    background: #fff;
}

.social h1 {
    margin: 0;
    padding: 0;
    font-family: Calibri;
    font-size: 40px;
    color: #000;
    letter-spacing: 50px;
}
Was it helpful?

Solution

The simplest way is to move the letter-spacing style to the .social div and animate it there, using the same animate function call as for the width.

JSFiddle Demo

.social {
    letter-spacing: 50px;
    ...
}
...
$(this).stop().animate({ width: '150px', letterSpacing: '0px' }, 500);
...
$(this).stop().animate({ width: '50px', letterSpacing: '50px' }, 500);

OTHER TIPS

You need to set the letter-spacing to a valid value:

$('.social h1').css({'letter-spacing': 'normal'}, 1000);

Is there anything else you were having a problem with? That's is the only question I could glean from your post.

EDIT:

$('.social h1').animate({'letter-spacing': 'normal'}, 1000);

If you are trying to animate the letter-spacing this works with jQuery 1.8.1+

$('.social h1').animate({'letter-spacing': '0px'}, 5000)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top