我有一個圓,由12個圓弧段組成,我想讓用戶看到從開始模式到結束模式的轉換。 (會有很多開始和結束模式)。javascript/css中的連續動畫
我已經在css文件中包含transition屬性,所以這不是問題。
這裏是到目前爲止我的代碼:
function playAnimations(){
console.log("gets inside playanimations")
var totalLength = document.getElementsByClassName("container")[0].children.length
console.log(totalLength)
for(var i = 0; i < totalLength; i++){
var current_pattern = document.getElementsByClassName("container")[0].children[i]
for(var j = 0; j < 12; j++){
$('#LED' + (j+1)).css('transition-duration', '0s');
$('#LED' + (j+1)).css({fill: current_pattern.children[1].children[j].style.backgroundColor});
}
for(var k = 0; k < 12; k++){
$('#LED' + (k+1)).css('transition-duration', "" + current_pattern.children[3].children[0].value + "ms");
$('#LED' + (k+1)).css({fill: current_pattern.children[2].children[k].style.backgroundColor});
}
}
}
for循環外通過所有的圖案橫穿而內兩個for循環遍歷該特定圖案的開始和結束值。我遇到的問題是,我只能看到圓上的最終顏色,而不是開始顏色。
有誰知道一個很好的解決方法,或者我可以做些什麼來糾正這個問題?任何反饋或幫助表示讚賞。
問題是,你不會讓任何時間過渡,你設置一種顏色,並立即設置下一個。在設置下一個顏色之前,您需要使用setTimeout。如果你用你迄今爲止的工作代碼搭建一個jsfiddle,那麼制定答案會更容易。 – ariel
您提供的代碼只是[mcve]。通過添加最小的HTML和CSS,您可能會得到更快,更可靠的答案。 –
所以,如果你找到答案,http://stackoverflow.com/help/self-answer – ariel