$(document).ready(function() {
$('.reviews__text').each(function() {
if ($(this).text().length > 391) {
$(this).data('full', $(this).text());
$(this).text($(this).text().slice(0, 391) + '...');
$(this).after("<span class='reviews__more'>Развернуть</span>");
}
});
$('.reviews__more').click(function() {
if ($(this).text() == 'Развернуть') {
$(this).siblings('.reviews__text').text($(this).siblings('.reviews__text').data('full'));
$(this).text('Свернуть');
} else {
$(this).siblings('.reviews__text').text($(this).siblings('.reviews__text').text().slice(0, 391) + '...');
$(this).text('Развернуть');
}
});
});
$('.reviews__text').each(function() {
if ($(this).height() > 288) {
$(this).data('height', $(this).height());
$(this).css('maxHeight', '288px');
$(this).after("<span class='reviews__more'>Развернуть</span>");
}
});
$('.reviews__more').click(function() {
if( $(this).text() == 'Развернуть' ) {
$(this).siblings('.reviews__text').animate({maxHeight: $(this).siblings('.reviews__text').data('height') }, 400);
$(this).text('Свернуть');
} else {
$(this).siblings('.reviews__text').animate({maxHeight: '288px'}, 400);
$(this).text('Развернуть');
}
});
$('.reviews__text').each(function() {
if ($(this).height() > 288) {
$(this).data('height', $(this).height());
$(this).css('height', '288px');
$(this).after("<span class='reviews__more'>Развернуть</span>");
}
if ($(this).text().length > 424) {
$(this).data('full', $(this).text());
$(this).text( $(this).text().slice(0, 424) + '...' );
}
});
$('.reviews__more').click(function() {
if( $(this).text() == 'Развернуть' ) {
$(this).siblings('.reviews__text').animate({height: $(this).siblings('.reviews__text').data('height') }, 424);
$(this).siblings('.reviews__text').text( $(this).siblings('.reviews__text').data('full') );
$(this).text('Свернуть');
} else {
$(this).siblings('.reviews__text').animate({height: '288px'}, 200);
$(this).siblings('.reviews__text').text( $(this).siblings('.reviews__text').text().slice(0, 424) + '...' );
$(this).text('Развернуть');
}
});
$(document).ready(function() {
$('.reviews__text').each(function() {
if ($(this).text().length > 391) {
$(this).data('full', $(this).text() );
$(this).html($(this).text().slice(0, 391) + '... <span class="volt">'+$(this).text().slice(391, 99999)+'</span>' );
$(".volt").hide()
$(this).after("<span class='reviews__more'>Развернуть</span>");
}
});
$('.reviews__more').click(function() {
if ($(this).text() == 'Развернуть') {
$(".volt").show(function(){
$(this).addClass('animated slideInDown')
})
$(this).text('Свернуть');
} else {
$(".volt").hide(function(){
$(this).addClass('animated slideInDown')
})
$(this).text('Развернуть');
}
});
});
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css" rel="stylesheet">
$('.reviews__text').each(function() {
if ($(this).text().length > 391) {
$(this).data('full', $(this).text() );
$(this).html($(this).text().slice(0, 391) + '... <span class="volt">'+$(this).text().slice(391, 99999)+'</span>' );
$(".volt").hide()
$(this).after("<span class='reviews__more'>Развернуть</span>");
}
});
$('.reviews__more').click(function() {
if ($(this).text() == 'Развернуть') {
$(this).siblings('.reviews__text').find('.volt').slideDown();
$(this).text('Свернуть');
} else {
$(this).siblings('.reviews__text').find('.volt').slideUp();
$(this).text('Развернуть');
}
});
$('.reviews__text').each(function() {
if ($(this).text().length > 391) {
$(this).parent('.reviews__wrapper').data('height', $(this).parent('.reviews__wrapper').height());
$(this).data('full', $(this).text());
$(this).text($(this).text().slice(0, 391) + '...');
$(this).parent('.reviews__wrapper').css('height', '303px');
$(this).after("<span class='reviews__more'>Развернуть</span>");
}
});
$('.reviews__more').click(function() {
var trigger = $(this); // Кнопка свернуть/развернуть
var feedback_text = trigger.siblings('.reviews__text').data('full'); //Текст отзыва
var feedback_container = trigger.siblings('.reviews__text'); //Контейнер текста
var feedback_container_wrapper = trigger.parent('.reviews__wrapper'); //Обёртка для контейнера
if (trigger.text() == 'Развернуть') {
feedback_container_wrapper.animate({height: feedback_container_wrapper.data('height') + 23 }, 400);
feedback_container.text(feedback_text);
trigger.text('Свернуть');
} else {
feedback_container_wrapper.animate({height: '303px'}, 400);
feedback_container.text( feedback_text.slice(0, 391) + '...' );
trigger.text('Развернуть');
}
});
$.animate({
"height": "100px" //изменяемое свойство
},
500, //длительность анимации
function(){
//место для тела анонимной функции, которая выполнится, после завершения анимации
});