[英]CSS3 Transitions not working on width and height of canvas element
我使用firefox 24.0進行開發。
我的代碼中有這個元素
唯一身份
.t_Bubble > canvas:nth-child(1)
外部HTML內容
<canvas style="width: 50px; height: 73px;" height="73" width="50"></canvas>
它稍后會在代碼的后半部分更改為此HTML內容。
<canvas style="width: 114px; height: 62px;" height="62" width="114"></canvas>
我已經在這個元素上應用了這個css
.t_Bubble > canvas:nth-child(1){
transition: width 2s ease,height 2s linear;
-moz-transition:width 2s ease, height 2s linear;
-webkit-transition:width 2s ease, height 2s linear;
}
但是在瀏覽器中不會發生任何轉換。 你能幫幫我嗎? 謝謝
我剛嘗試過 ,它對我有用。 所以我說的完全wrong
。
所以我的猜測是你的CSS不適用於畫布,由於選擇器中的錯誤。
你可以分享你的HTML嗎?
另外,使用:first-child
而不是:nth-child(1)
它有更好的支持
簡短回答:您可能沒有使用CSS選擇器正確定位canvas元素。
長'回答':我認為有幾點需要注意:
canvas
標記的height
或width
屬性將完全清除它(即刪除任何繪制到它的內容,將其重置為空白平板)。 (雖然顯然,在某些瀏覽器中不會發生這種情況。) <canvas>
元素, height
或width
屬性與height
和width
的CSS屬性有唯一的關系,我在這里描述: https : //stackoverflow.com/a/19079320/1937302 height
或width
屬性的更改將不會 “轉換”/動畫 height
或width
屬性的CSS特性的更改將被 “轉換”/動畫化 我在這里演示了一些:
http://jsfiddle.net/BYossarian/WWtGZ/3/
HTML:
<canvas id="canvas1" height="50" width="100"></canvas>
CSS:
canvas {
border: 1px solid black;
transition: all 1s ease;
height: 50px;
}
JS:
var canvas = document.getElementById('canvas1'),
ctx = canvas.getContext('2d');
ctx.fillStyle = "red";
ctx.fillRect(10, 10, 30, 30);
// changing width attribute clears canvas element (in most broswers)
// changing width attribute isn't animated by CSS transition
setTimeout(function () {
canvas.width = "200";
}, 2000);
// changing CSS rule for width is animated, although if no CSS rule for width already exists, then a width of 0px is taken as the starting point
setTimeout(function () {
ctx.fillStyle = "red";
ctx.fillRect(10, 10, 30, 30);
canvas.style.width = "100px";
}, 4000);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.