【发布时间】:2017-03-07 23:28:12
【问题描述】:
我想知道,当您从顶部向下滚动 1000 像素或在屏幕上看到它时,如何让这个动画开始?
我尝试了不同的方法并且零运气,它会在网站加载时自动启动。
$(".progress div").each(function() {
var display = $(this),
currentValue = parseInt(display.text()),
nextValue = $(this).attr("data-values"),
diff = nextValue - currentValue,
step = (0 < diff ? 1 : -1);
if (nextValue == "0") {
$(display).css("padding", "0");
} else {
$(display).css("color", "#fff").animate({
"width": nextValue + "%"
}, "slow");
}
});
.progress-bar {
background-color: #53dceb;
height: 12px;
-webkit-transition: width 1.5s ease-in-out;
transition: width 1.5s ease-in-out;
}
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<div style="margin-bottom: 2rem">
<h5 style="color: #666">test12 <span class="pull-right">50%</span></h5>
<div class="progress">
<div data-values="50" class="progress-bar" style="color: rgb(255, 255, 255);"></div>
</div>
</div>
【问题讨论】:
-
你试过 .scroll() 事件吗? :)
-
对解释性问题投赞成票
标签: javascript jquery