_toggle
is defined inside the .click
scope. It needs to be scoped further up for this to work:
// Move _toggle to here
var _toggle = 0;
$('.copy-more').click(function(){
var _header;
var _sum;
var _full;
var _opacity;
var _text;
if ( _toggle === 0) {
_header = 120;
_sum = 150;
_full = 220;
_opacity = 1;
_text = "Read Less";
_toggle = 1;
}
else {
_header = 310;
_sum = 345;
_full = 420;
_opacity = 0;
_text = "Read More";
_toggle = 0;
}
$('.slide-header').animate({'top': _header}, 150);
$('.copy-sum').animate({'top': _sum}, 250);
$('.copy-full').animate({'top': _full, 'opacity': _opacity}, 500);
$('.copy-more').animate({'opacity': 0}, 500, function () {
$(this).text(_text);
}).animate({'opacity': 1}, 500);
});
However, you should look into .toggleClass and CSS3 animations instead - much cleaner