我有一个增加数字的工作函数,我在自定义数据字段中使用它。
脚本
$(document).ready(function(){
$(".servCon").children(".eaService").each(function(i) {
$(this).attr('data-wow-delay', '0.' + (i+1) + '0s');
});
});
HTML输出
<div class="servCon">
<div class="eaService" data-wow-delay="0.1s"></div>
<div class="eaService" data-wow-delay="0.2s"></div>
<div class="eaService" data-wow-delay="0.3s"></div>
<div class="eaService" data-wow-delay="0.4s"></div>
<div class="eaService" data-wow-delay="0.5s"></div>
<div class="eaService" data-wow-delay="0.6s"></div>
<div class="eaService" data-wow-delay="0.7s"></div>
<div class="eaService" data-wow-delay="0.8s"></div>
<div class="eaService" data-wow-delay="0.9s"></div>
<div class="eaService" data-wow-delay="0.1s"></div>
<div class="eaService" data-wow-delay="0.11s"></div>
<div class="eaService" data-wow-delay="0.12s"></div>
</div>
我的问题是&#34; 0.9s&#34;它可以追溯到&#34; 0.1s&#34;然后&#34; 0.11s&#34;但是喜欢它的事情是&#34; 0.9s&#34;转到&#34; 1.0s&#34;然后&#34; 1.1s&#34;等等#34; 1.9s&#34;到&#34; 2.0s&#34;等等。感谢
答案 0 :(得分:4)
尝试这样做,
$(document).ready(function(){
$(".servCon").children(".eaService").each(function(i) {
$(this).attr('data-wow-delay', parseFloat((i+1)/10).toFixed(1) + 's');
});
});
这个想法背后的概念,
index + 1
= 10
(如果索引为9
)index + 1 / 10
将为1
(1).toFixed(1)
将为1.0