[英]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.