All,
I am trying create a 'to & fro' animation using jquery animate & css transform property.
I referred to this SO post on using step function in animate, however, Im not having much success. Please review & advice.
HTML:
<ul id="a">
<li class="cAccessories" id="AccButtons"><span>blah blah..</span></li>
<li class="cAccessories" id="AccRibbons"><span>blah blah..</span></li>
<li class="cAccessories" id="AccLaces"><span>blah blah..</span></li>
<li class="cAccessories" id="AccEmbroider"><span>blah blah..</span></li>
</ul>
CSS:
#a {
position: absolute;
top: 25px;
left: 25px;
width: 150px;
height: 150px;
padding: 0;
margin: 0;
list-style: none;
background-color: blue;
}
JAVASCRIPT:
$("#a").animate ({"margin-left": "+=10px"}, {step: function (now, fx) {
$("#a").css ("-moz-transform", "rotate('5deg')");
$("#a").css ("-webkit-transform", "rotate ('5deg')");
$("#a").css ("-ms-transform", "rotate ('5deg')");
$("#a").css ("-o-transform", "rotate ('5deg')");
}, duration: "slow"}, "linear", function ()
{
$("#a").animate ({left: "+=0px"}, {step: function (now, fx) {
$("#a").css ("-webkit-transform", "rotate ('-5deg')");
$("#a").css ("-moz-transform", "rotate ('-5deg')");
$("#a").css ("-ms-transform", "rotate ('-5deg')");
$("#a").css ("-o-transform", "rotate ('-5deg')");
}, duration: "slow"}, "linear" ); });
Following is the original code, which I doesn't like the transform animation (even though it animates the 'top' value perfectly).
iTemplateNo = $(this).attr("id").substr (-1, 1);
eCurHanger = document.getElementById("hanger0" + iTemplateNo);
$(eCurHanger).attr("src", "Img/V2/Hanger.png");
$(eCurHanger).css ({"width": "45px", "height": "35px"});
$(eCurHanger).animate ({top: "+=10px"}, {step: function (angle, fx) {
$(eCurHanger).css ({"-webkit-transform": "rotate ("+angle+"deg)",
"-moz-transform": "rotate ("+angle+"deg)",
"-ms-transform": "rotate ("+angle+"deg)",
"-o-transform": "rotate ("+angle+"deg)"});
}, duration: 1000}, "linear", function ()
{
$(eCurHanger).animate ({left: "+=10px"}, {step: function (angle, fx) {
$(this).css ({"-webkit-transform": "rotate("+angle+"deg)",
"-moz-transform": "rotate("+angle+"deg)",
"-ms-transform": "rotate("+angle+"deg)",
"-o-transform": "rotate("+angle+"deg)"})
}, duration: 1000}, "linear" ) });
I do not know what
eCurHanger
is, but look here http://jsfiddle.net/8tP9D/instead of global
angle
you could usenow
variable. http://jsfiddle.net/39pe6/Researched a bit. There were certain syntax errors. Here is the output you require I think Click Here!.
The code working with me is here: