...似乎没有应用过渡。
哦,但确实如此!您只需从小提琴的 CSS 代码中删除两个拼写错误:
-
display: inline-block; 在任何选择器括号之外
- 以
// 开头的评论,而不是使用/*...*/
这是您的corrected fiddle,效果很好。
只剩下一个问题了:
Ken Burns 效果仅从第二张幻灯片开始。这是因为第一张幻灯片立即从“活动”类开始,而不是过渡到它。所以它从 scale:1.5 开始(应该是过渡的结束值)。
一种解决方案可能是使用 CSS 关键帧动画而不是过渡。但在这种情况下,使用一点 JS 会容易得多。引导轮播无论如何都使用 JS 通过将类附加/分离到项目来从幻灯片切换到幻灯片。
这是一个解决方案(也被清理了一点),它使用了一个额外的类“inactiveUntilOnLoad”,它在加载时中和了“active”类,并且它在 DOM 就绪事件中被移除,因此转换将从第一张幻灯片开始:
jsFiddle working from first slide
底线:
以下是“Ken Burns”原始 Bootstrap 3 轮播所需的所有更改:
CSS 更改
为.carousel .item img 定义转换,
定义.carousel .item img 的启动状态,
定义.carousel .item.active img 的结束状态,
还将选择器.carousel .item.active.inactiveUntilOnLoad img 添加到开始状态的定义中以创建第一帧的动画。
/* transition */
.carousel .item img {
-webkit-transition: all 5s;
-moz-transition: all 5s;
-o-transition: all 5s;
transition: all 5s;
}
/* start status */
.carousel .item img,
.carousel .item.active.inactiveUntilOnLoad img {
-webkit-transform: scale(1);
-moz-transform: scale(1);
-o-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
}
/* end status */
.carousel .item.active img {
-webkit-transform: scale(1.5);
-moz-transform: scale(1.5);
-o-transform: scale(1.5);
-ms-transform: scale(1.5);
transform: scale(1.5);
}
HTML 更改
将类 .inactiveUntilOnLoad 添加到第一个(活动)项目。
<div class="item active inactiveUntilOnLoad">
JS 变化
将代码添加到 DOM 就绪事件以删除类 .inactiveUntilOnLoad。
$(function() {
$('.inactiveUntilOnLoad').removeClass('inactiveUntilOnLoad');
});