Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery animation: How to move a value from the left to the right and back?
    primarykey
    data
    text
    <p>I would like to move a value in a class from the left to the right and back after clicking on any star. Below picture may help to imaging what I am trying to achieve. In this case I want the "4.0" move to the right and back after I click on a star. (The 4.0 is a generated value from Rails.)</p> <p><img src="https://i.stack.imgur.com/4zuyv.jpg" alt="enter image description here"></p> <p>I am trying to apply the following code from <a href="http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_animation1" rel="nofollow noreferrer">w3schools</a>. It does work in the example on <a href="http://jsfiddle.net/tHLuE/" rel="nofollow noreferrer">jsfiddle</a>, but it doesn't work in my code. Everything else works just fine.</p> <p>What am I missing here? Many thanks. </p> <p><strong>HTML</strong></p> <pre><code> &lt;ul&gt; &lt;li&gt;&lt;a href="#/routes/1"&gt;Route 1&lt;/a&gt; &lt;div id="Route1" class="rate_widget"&gt; &lt;div class="star_1 ratings_stars &lt;%= Score.average('score', :conditions =&gt; 'route_id = 1') &gt;= 1 ? "ratings_vote" : "" %&gt;" data-score="1"&gt;&lt;/div&gt; &lt;div class="star_2 ratings_stars &lt;%= Score.average('score', :conditions =&gt; 'route_id = 1') &gt;= 2 ? "ratings_vote" : "" %&gt;" data-score="2"&gt;&lt;/div&gt; &lt;div class="star_3 ratings_stars &lt;%= Score.average('score', :conditions =&gt; 'route_id = 1') &gt;= 3 ? "ratings_vote" : "" %&gt;" data-score="3"&gt;&lt;/div&gt; &lt;div class="star_4 ratings_stars &lt;%= Score.average('score', :conditions =&gt; 'route_id = 1') &gt;= 4 ? "ratings_vote" : "" %&gt;" data-score="4"&gt;&lt;/div&gt; &lt;div class="star_5 ratings_stars &lt;%= Score.average('score', :conditions =&gt; 'route_id = 1') == 5 ? "ratings_vote" : "" %&gt;" data-score="5"&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="total_votes"&gt;&lt;%= "%0.1f" % Score.average('score', :conditions =&gt; 'route_id = 1') %&gt;&lt;/div&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p><strong>CSS</strong></p> <pre><code>.ratings_stars { background: url('star_empty.png') no-repeat; float: left; height: 28px; padding: 2px; width: 32px; } .total_votes { background: yellow; top: -10px; margin: 12px 0px 10px 0px; padding: 1px 0px 0px 5px; position: relative; width: 170px; height: 17px; line-height: 1; color: red; } </code></pre> <p><strong>jQuery</strong></p> <pre><code>// This records the vote $('.ratings_stars').on('click', function() { var score=$(this).attr("data-score"); var route_id=$(this).parent().attr("id").replace('Route', ''); // This moves the score to the right $('.ratings_stars').click(function() { $('.total_votes').animate({left:'50px'}, 500) $('.total_votes').animate({left:'0px'}, 500); }); $.post( '/scores', // this sends the voting data to the page '/scores' { "score[score]": score, "score[route_id]": route_id }, function() { alert('Thank you for your vote.'); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload