setTimeout関数を使用して、JavaScriptで各関数を実行するときにエフェクトに遅延を追加します。JavaScriptの各関数にSetTimeoutを使用すると奇妙な反応が発生する
最初のループはうまく動作しますが、上にスクロールして再び下にスクロールすると、アイコンにグリッチがあります。
HTMLコード
<div id="box"></div>
<div class="service-modules-section">
<div class="service-modules">
<div class="half service-row-left">
<div class="service-item">
<div class="icon-wrap">
<img alt="Canadian News Reporting Icon" class="img-fluid" src="http://icons.iconarchive.com/icons/vcferreira/firefox-os/128/sms-icon.png" style="display: inline;" width=50px>
</div>
<div class="service-meta">
<h3>News Reporting</h3>
<p>From breaking national, regional and world news to the biggest events in politics, sports, business and entertainment, we are there when it matters, delivering news about Canadians to Canadians, 24/7.ok.</p> </div>
<div class="clearfix"></div>
</div>
<div class="service-item">
<div class="icon-wrap">
<img alt="Canadian News Reporting Icon" class="img-fluid" src="http://icons.iconarchive.com/icons/vcferreira/firefox-os/128/sms-icon.png" style="display: inline;" width=50px>
</div>
<div class="service-meta">
<h3>News Reporting</h3>
<p>From breaking national, regional and world news to the biggest events in politics, sports, business and entertainment, we are there when it matters, delivering news about Canadians to Canadians, 24/7.ok.</p> </div>
<div class="clearfix"></div>
</div>
<div class="service-item">
<div class="icon-wrap">
<img alt="Canadian News Reporting Icon" class="img-fluid" src="http://icons.iconarchive.com/icons/vcferreira/firefox-os/128/sms-icon.png" style="display: inline;" width=50px>
</div>
<div class="service-meta">
<h3>News Reporting</h3>
<p>From breaking national, regional and world news to the biggest events in politics, sports, business and entertainment, we are there when it matters, delivering news about Canadians to Canadians, 24/7.ok.</p> </div>
</div>
</div>
</div>
<div id="box"></div>
CSSコード:
#box {
height: 600px;
}
.service-modules-section{
position: relative;
}
img {
display: none;
position: relative;
top: 90px;
}
のJavaScriptコード:
var speed = 500;
var waypoint = new Waypoint({
element: $('.icon-wrap').children(),
handler: function(direction) {
$('.icon-wrap').children().each(function(k, v){
var el = this;
setTimeout(function(){
$(el).animate({
'opacity': '70'
}, {
step: function (now, fx) {
$(el).css({"transform": "translate3d(0px, " + -now + "px, 0px)"});
},
duration: 1000,
easing: 'linear',
queue: false,
complete: function() {
// alert('Animation is done');
}
}, 'linear');
$(el).animate({ textIndent: 100 }, {
duration : 1000,
easing: 'linear',
queue: false
});
}, k*speed);
})
if(direction === "up"){
$('.icon-wrap').children().css('top', '100px');
}
}, offset: '75%'
});
任意のアイデア何が起こるか?おかげで、
https://codepen.io/techcater/pen/jwJZZe
- https://stackoverflow.com/questions/10840106/settimeout-in-a-jquery-animation – mplungjan
おかげ@mplungjan、私はそれを見てみましょう。 –
var elを変更して、elにするようにしてください... –