我試圖創建使用jQuery動畫& CSS變換屬性「來&回回」的動畫。
我參考this SO發表在使用step動畫功能的動畫,但是,我沒有太大的成功。請回顧&的建議。
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"); });
以下是原始代碼,我不喜歡轉換動畫(儘管它完美地爲'頂部'值設置動畫效果)。
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") });
什麼是'eCurHanger'? – Cheery 2012-02-16 07:43:28
我的歉意,我已經改變了代碼,並忘記了這一點。 – Kayote 2012-02-16 08:11:43
注意從jQuery變換cssHooks – noob 2012-02-16 11:55:53