親スライドがビューポートに移動したときに、ネストされたDIVのコンテンツをアニメーション化するためにjavascriptを使用したいと考えています。アニメーション化された親スライドがスクロールを使わずにビューポートに移動するときにネストされたコンテンツをアニメーション化する方法
現在のところ、ネストされたDIVのコンテンツは、親スライドが画面に移動した後にスクロールコマンドがトリガーされたときにのみアニメーション化されます。これは、スライドの動きがアニメーション化され、スクロール制御されていないためです。
同じ問題は、私は問題を探求するために作成され、このJSFiddleデモで遊んでいる:
(このデモでは、右から左へのスライドのアニメーションの動きをテストするために作成されていますこの問題は、スクロールせずにスライドの動きを再現するためのものであり、実際には適切な開発の特徴ではありません)。
私の質問は、各スクロール要素がスクロール機能を必要とせずにビューポートに移動するときに、ネストされたDIVごとにアニメーションをトリガーする方法は何ですか?
ありがとうございました。ここでは、不透明度やその他のCSSスタイルを制御するために使用しているスクリプトを示します。
$(document).ready(function() {
/* Every time the window is scrolled ... */
$(window).scroll(function() {
/* Reveal hidden_header delayed */
$('.hidden_header').each(function(i) {
var center_of_object = $(this).offset().left + $(this).outerWidth();
var center_of_window = $(window).scrollLeft() + $(window).width();
/* If the object is completely visible in the window, fade it it */
if (center_of_window > center_of_object) {
$(this).animate({
'opacity': '1'
}, 500);
$(this).animate({
'right': '0'
}, 1500);
}
});
/* Reveal hidden_content delayed */
$('.hidden_content').each(function(i) {
var center_of_object = $(this).offset().left + $(this).outerWidth();
var center_of_window = $(window).scrollLeft() + $(window).width();
/* If the object is completely visible in the window, fade it it */
if (center_of_window > center_of_object) {
$(this).animate({
'opacity': '1'
}, 3000);
$(this).animate({
'bottom': '0'
}, 3500);
}
});
/* Reveal button delayed */
$('.button').each(function(i) {
var center_of_object = $(this).offset().left + $(this).outerWidth();
var center_of_window = $(window).scrollLeft() + $(window).width();
/* If the object is completely visible in the window, fade it it */
if (center_of_window > center_of_object) {
$(this).animate({
'opacity': '1'
}, 5000);
}
});
});
});
もちろん、これは最も洗練されたソリューションです。よく目に付き、助けてくれてありがとう! :D – Mook81