スクロール位置に基づいて要素を(連続して独立して)アニメーション表示しようとしています。スクロール位置に基づくアニメーション
目的は、各要素をループし、ユーザーのスクロール位置に基づいて回転を変更することです。今、各アイテムの回転は常に同じです。これはどのように達成できますか?ここで
はフィドルです:https://jsfiddle.net/nfquerido/wy84pLud/
そして、これはループ機能である:
var _items = function() {
forEach(items, function(item) {
var scrollTop = _scrollTop(),
elementTop = item.offsetTop,
documentHeight = _getDocumentHeight(),
elementHeight = _getElementHeight(item),
// Transform the item based on scroll
rotation = (scrollTop/(documentHeight - windowHeight) * 360),
transform = 'rotate(' + rotation + 'deg)';
// Elements off the top edge.
if (scrollTop > elementTop) {
item.classList.add('scrolling');
item.style.webkitTransform = transform;
} else {
item.classList.remove('scrolling');
item.style.webkitTransform = null; // Reset the transform
}
});
};
私はバニラJavaScriptの提案をしてくださいいただければと思います!私は回転VARのあなたの割り当ての上にこの権利を追加
:
要素レベルに対する効果 :https://jsfiddle.net/nfquerido/wy84pLud/5/ – nfq