Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Sandy Bay
249 PointsjQuery function call on button click doesn't work after one click
Hello! I'm trying to animate elements placed in a circle using jQuery. I need the parent div to animate by a specific angle every time I click a button. This angle is calculated by a function. My issue is the rotation happens once but after that the button click doesn't work. I'm using the jQuery Rotate plugin for the rotation. Here is my code:
var nextAngle=0; function getNextAngle(){ nextAngle = nextAngle+40; reduceAngle -= 40; return nextAngle; };
$('#next').on("click",function(){
$('.circle_container').rotate({animateTo: getNextAngle()});
$('.sliders').rotate({animateTo:reduceAngle});
});
1 Answer

Steven Parker
225,730 PointsWhere is reduceAngle declared?
It didn't work even once for me, until I added this line:
var reduceAngle = 0;
After that, it worked on every button press.
To enable a more complete analysis, provide all the code, including the HTML and CSS components. Or if you're using a workspace, make a snapshot of your workspace and post the link to it here.

Sandy Bay
249 Pointssome CSS was causing the issue, I figured it out. Will provide snapshots for my future questions, thanks for the heads up Steve!
Steven Parker
225,730 PointsSteven Parker
225,730 PointsWhen posting code, always use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area.