重新触发动画
Retriggering an animation
您好!我正在尝试实现一个进度条,当点击一个按钮时,它将被填充一些量。我发现这是一个非常有用的基础:http://css-tricks.com/css3-progress-bars/
增加栏的归档量的方法是修改span
元素的width:
属性,该属性基本上是javascript:的1行
document.getElementById("this").style.width = "35%";
问题是,尽管它可以工作,但填充动画不会被触发。我在这里搜索了有模拟问题的人,我发现:如何通过JavaScript重新触发WebKit CSS动画?
它提供了一些我试图在代码中实现的解决方案。它们似乎都不起作用,所以我决定做一个新线程。整个源代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Tt1</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<style>
.meter {
width:15%;
height: 20px;
position: relative;
margin: 60px 0 20px 0;
background: #555;
padding: 10px;
}
.meter > span {
display: block;
height: 100%;
background-color: rgb(43,194,83);
background-image: -webkit-gradient(
linear,
left bottom,
left top,
color-stop(0, rgb(43,194,83)),
color-stop(1, rgb(84,240,84))
);
background-image: -moz-linear-gradient(
center bottom,
rgb(43,194,83) 37%,
rgb(84,240,84) 69%
);
position: relative;
overflow: hidden;
}
.meter > span:after, .animate > span > span {
content: "";
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
background-image:
-webkit-gradient(linear, 0 0, 100% 100%,
color-stop(.25, rgba(255, 255, 255, .2)),
color-stop(.25, transparent), color-stop(.5, transparent),
color-stop(.5, rgba(255, 255, 255, .2)),
color-stop(.75, rgba(255, 255, 255, .2)),
color-stop(.75, transparent), to(transparent)
);
background-image:
-moz-linear-gradient(
-45deg,
rgba(255, 255, 255, .2) 25%,
transparent 25%,
transparent 50%,
rgba(255, 255, 255, .2) 50%,
rgba(255, 255, 255, .2) 75%,
transparent 75%,
transparent
);
z-index: 1;
-webkit-background-size: 50px 50px;
-moz-background-size: 50px 50px;
-webkit-animation: move 2s linear infinite;
overflow: hidden;
}
.animate > span:after {
display: none;
}
@-webkit-keyframes move {
0% {
background-position: 0 0;
}
100% {
background-position: 50px 50px;
}
}
.nostripes > span > span, .nostripes > span:after {
-webkit-animation: none;
background-image: none;
}
</style>
</head>
<body>
<div id="aa" class="meter">
<span id="this" style="width: 15%"></span>
</div>
<button onclick="asd()">asd</button>
</body>
</html>
<script>
function asd() {
document.getElementById("this").style.width = "35%";
document.getElementById("aa").style.animationName = "";
document.getElementById("aa").style.animationName = "move 2s";
document.getElementById("aa").style.webkitAnimationName = "";
document.getElementById("aa").style.webkitAnimation = "move 2s linear infinite";
}
//k
$(".meter > span").each(function () {
$(this)
.data("origWidth", $(this).width())
.width(0)
.animate({
width: $(this).data("origWidth")
}, 1200);
});
</script>
我在.meter > span:after, .animate > span > span
中添加了-webkit-transition:all 0.5s;
,它似乎运行良好。http://jsfiddle.net/VjHWr/
你试过吗
this.style.width = "35%";
相关文章:
- Raphael:单独触发多个路径动画
- 从javascript代码触发ngFx动画
- 在React中,如何立即触发动画,而不是让它们排队
- 在新标签页打开时触发 Chrome 扩展程序
- 通过javascript触发CSS动画
- 在子控制器中触发时,Ionic AngularJS父动画未正确运行
- css动画没有'不使用新的dom元素
- 如何正确地链接调用$.show()和$.thoggClass()来触发CSS3动画
- 为什么单击时的关键帧动画只触发一次
- 你如何使动画不触发,除非完成之前(不使用回调)
- ng动画不触发动画
- Flot图表在动画上触发错误
- 在使滚动动画不触发滚动事件时遇到问题
- 使用jQuery时,防止使用动画scrollTop触发滚动事件
- jQuery动画不触发回调函数
- 动画新创建的列表元素
- 回调中的动画没有触发,SnapSVG
- 在Angular JS中,如何在动画之后触发控制器函数
- Jquery动画不触发的变化
- 动画期间触发更新