與動畫
基本上和改造你必須使用jQuery的animate函數的階躍函數這看起來有點像這樣:
$('.animate').animate({
'opacity': '320'
}, {
step: function (now, fx) {
$(this).css({"transform": "translate3d(0px, " + now + "px, 0px)"});
},
duration: 10000,
easing: 'linear',
queue: false,
complete: function() {
alert('Animation is done');
}
}, 'linear');
你將不得不單獨設置文本縮進,但基本上你做錯了什麼,每次調用step函數時,值都被設置爲320px,而不是像它那樣。這可以通過使用兩個單獨的函數並使用不重要的CSS規則來創建跨動畫曲線所需的值來解決。你還需要將隊列設置爲false,這樣兩個動畫發生在同一時間,而不是一個代碼的其他
的最終代碼段後應該是這樣的:
$('.animate').animate({
'opacity': '320'
}, {
step: function (now, fx) {
$(this).css({"transform": "translate3d(0px, " + now + "px, 0px)"});
},
duration: 10000,
easing: 'linear',
queue: false,
complete: function() {
alert('Animation is done');
}
}, 'linear');
$(".animate").animate({ textIndent: 100 }, {
duration : 10000,
easing: 'linear',
queue: false
});
這裏是一個工作小提琴:
http://jsfiddle.net/Hive7/1qu2qxqh/
您是否嘗試過使用像這個人寫的那樣的幫助函數? http://cameronspear.com/blog/animating-translate3d-with-jquery/ – Larz 2014-12-04 19:52:26