Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery, animating an element from it's center
    primarykey
    data
    text
    <p>I have some elements on a page that I am animating via jquery.</p> <p>I'm having some minor trouble in figuring out how to have the circles animate from the center of the circle's (not the top left corner that Jquery animates, defaultly)</p> <p>Consider the following:</p> <pre><code> var percentage = $("#percent"); var percentage2 = $("#percent2"); var percentage3 = $("#percent3"); var nCircleA = 0; var nCircleB = 0; var nCircleC = 0; function myClick() { /*answer1*/ $('ul#quiz li').on("click", function() { if ($(this).hasClass('active') === false) { $(this).addClass('active'); $(this).siblings().addClass('deactive'); $(this).siblings().removeClass('active'); $(this).removeClass('deactive'); if ($(this).hasClass('active') &amp;&amp; $(this).is('.viewa')) { circle1animate(); circle2deactive(); circle3deactive(); } if ($(this).hasClass('active') &amp;&amp; $(this).is('.viewb')) { circle2animate(); circle1deactive(); circle3deactive(); } if ($(this).hasClass('active') &amp;&amp; $(this).is('.viewc')) { circle3animate(); circle1deactive(); circle2deactive(); } } }); } function circle1animate() { percentage.html(++nCircleA); $('.circle1 img').animate({ width: "+=30.0%", height: "+=30.0%" }, 600, 'easeOutBounce'); } function circle2animate() { percentage2.html(++nCircleB); $('.circle2 img').animate({ width: "+=30.0%", height: "+=30.0%" }, 600, 'easeOutBounce'); } function circle3animate() { percentage3.html(++nCircleC); $('.circle3 img').animate({ width: "+=30.0%", height: "+=30.0%" }, 600, 'easeOutBounce'); } //deactive function circle1deactive() { percentage.html(nCircleA - 1 &lt; 0 ? 0 : --nCircleA); $('.circle1 img').animate({ width: "80px", height: "80px" }, 600, 'easeOutBounce').removeClass('trans'); } function circle2deactive() { percentage2.html(nCircleB - 1 &lt; 0 ? 0 : --nCircleB); $('.circle2 img').animate({ width: "80px", height: "80px" }, 600, 'easeOutBounce').removeClass('trans'); } function circle3deactive() { percentage3.html(nCircleC - 1 &lt; 0 ? 0 : --nCircleC); $('.circle3 img').animate({ width: "80px", height: "80px" }, 600, 'easeOutBounce').removeClass('trans'); } myClick(); </code></pre> <p><a href="http://jsfiddle.net/GregWebBandit/4f8qw/2/" rel="nofollow">JS FIDDLE</a></p>
    singulars
    1. This table or related slice is empty.
    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.
 

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