I have some buttons I'm trying to have rotate 45 degrees on click, but because I'm using a variable (or I think this is why) when a button is clicked it rotates 45 degrees, and then when another one is clicked because the variable has already been increased 45 degrees it goes 90. Is there a way to do this w/out variables or modify the set up I have so this doesn't' happen?
Here is the code and the setup in a demo: http://jsbin.com/atinap/16/edit
$(".info_btn").css("-webkit-transition", "-webkit-transform 0.25s ease-in-out");
var info_btn_DEG = 0;
$(".info_btn").toggle(function() {
$(this).closest('.article_wrapper').find('.description').slideDown("250");
info_btn_DEG += 45;
$(this).css("-webkit-transform", "rotateZ(" + info_btn_DEG + "deg)");
$(this).fadeTo("200", 0.65);
}, function() {
$(this).closest('.article_wrapper').find('.description').slideUp("200");
info_btn_DEG += 45;
$(this).css("-webkit-transform", "rotateZ(" + info_btn_DEG + "deg)");
$(this).fadeTo("250", 0.3);
});
any help with this would be amazing thanks
You need to associate an angle with each element, not have one global angle for all elements - use
.data()
: