パーツ番号 08-13-04 ・ JavaScript使用
方向連動で一時停止するローディングアニメ
下方向スクロール中はローダーが一時停止し、上方向スクロールに転じると回転が再開します。WordPressの読み込み演出や装飾アニメーションを、閲覧動作に合わせて制御したい場合に使えます。
プレビュー
ソースコード
HTML
<div class="d08-13-04-stage">
<div class="d08-13-04-loaderwrap">
<span class="d08-13-04-loader"></span>
<span class="d08-13-04-status">再生中</span>
</div>
<div class="d08-13-04-scroll">
<div class="d08-13-04-body">
<p>↓ 下スクロールで一時停止 / ↑ 上スクロールで再生再開</p>
<div class="d08-13-04-block"></div>
<div class="d08-13-04-block"></div>
<div class="d08-13-04-block"></div>
</div>
</div>
</div>CSS
.prev.d08-13-04{padding:0;display:block}
.d08-13-04-stage{position:relative;width:100%;height:100%;min-height:260px;overflow:hidden;background:#fff7ed}
.d08-13-04-loaderwrap{
position:absolute;top:14px;left:50%;transform:translateX(-50%);z-index:3;
display:flex;flex-direction:column;align-items:center;gap:6px;
}
.d08-13-04-loader{
width:44px;height:44px;border-radius:50%;
border:5px solid #fed7aa;border-top-color:#ea580c;
animation:d08-13-04-spin 1s linear infinite;
}
@keyframes d08-13-04-spin{to{transform:rotate(360deg)}}
.d08-13-04-stage.is-down .d08-13-04-loader{animation-play-state:paused}
.d08-13-04-status{font-size:11px;font-weight:700;color:#c2410c}
.d08-13-04-scroll{position:absolute;inset:0;overflow-y:auto;padding-top:88px}
.d08-13-04-body{padding:16px}
.d08-13-04-body p{font-size:11.5px;color:#c2410c;margin:0 0 12px;text-align:center}
.d08-13-04-block{height:80px;border-radius:8px;margin-bottom:12px;background:linear-gradient(135deg,#ffedd5,#fdba74)}JavaScript
(function(){
var stage=document.querySelector('.d08-13-04-stage');
if(!stage)return;
var scroller=stage.querySelector('.d08-13-04-scroll');
var status=stage.querySelector('.d08-13-04-status');
var last=0;
scroller.addEventListener('scroll',function(){
var top=scroller.scrollTop;
if(top>last+2){stage.classList.add('is-down');status.textContent='一時停止中';}
else if(top<last-2){stage.classList.remove('is-down');status.textContent='再生中';}
last=top<=0?0:top;
});
})();クラス名 .d08-13-04 は本ライブラリ内での識別用です。複数のパーツを同じページで使う場合は、重複しないよう名前を変更してください。