After trying some things I came up with the following solution:
I realised that creating in advance an array with all the heights of the <ul><li>
it responds quick enough to update correctly the height of the .Jcarousel div
.
JS
<script type="text/javascript">
$(document).ready(function(){
// checking the height of the first element in the <ul>
var count = 0;
var count_max = $(".jcarousel li").length;
var alturas = [];
$(".jcarousel li div.cenario").each(function(){
var height = $(this).height();
alturas.push(height);
});
$(".jcarousel").css('height',alturas[count]);
// changing height when pressing the prev control
$(document).on("click",".jcarousel-control-prev", function(){
if (count == 0) {
} else {
count = count-1;
$(".jcarousel").css('height',alturas[count]);
}
});
// changing height when pressing the next control
$(document).on("click",".jcarousel-control-next", function(){
if (count !== count_max) {
count = count+1;
$(".jcarousel").css('height',alturas[count]);
} else {
// trying to update the counter when reach the last <li> element within the <ul>
count = 0;
$(".jcarousel").css('height',alturas[count]);
}
});
});
</script>