small medium large xlarge

Generic-user-small
23 Aug 2012, 00:13
Bess Fernandez (5 posts)

Hi all,

I was having problems getting this chunk of code to work on page 145.

if ($('#cart tr').length == 1) { $('#cart').show('blind', 1000); } 
  
$('#cart').html("<%=j render @cart %>");

  $('#current_item').css({'background-color':'#88ff88'}).
    animate({'background-color':'#114411'}, 1000);

The blind animation never occurred when I added a new line item to an empty cart. I figured out that what I needed to do was render the cart first and then animate it in. Makes sense since it is set to display:none; from the helper. Here is my code:

if ($('#cart tr').length == 1) {  
    $('#cart').html("<%=j render @cart %>").show('slide', 1000);
} else {
    $('#cart').html("<%=j render @cart %>"); 
}

$('#current_item').css({'background-color':'#88ff88'}).animate({'background-color':'#114411'}, 1000);

Has anyone else run into this or I am I doing something magically strange here…?

Generic-user-small
23 Aug 2012, 18:09
Bess Fernandez (5 posts)

Ok, the reason why this wasn’t originally working is there were two divs with the id of cart. In the first example in application.html.erb the wrapping div is “cart”. In the later example of the cart as a helper there is a wrapping div with the id of cart. Remove the wrapping div in the application.html and you’ll be golden.

You must be logged in to comment