当父级幻灯片移动到视口中时,我正在使用JavaScript来为父幻灯片中的嵌套DIV的内容设置动画效果。如何在动画父级幻灯片移动到视口中时使用嵌套内容进行动画制作,而不是使用滚动
此刻,嵌套的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