3

我想在每个窗帘在中间相遇后立即暂停大约 20px 的滚动动画。这是我的沙箱:

http://www.meetgeraldine.net/2016website/luke-test/

jQuery:http ://snippi.com/s/vup8pw0

HTML:http ://snippi.com/s/bp5iceg

有没有办法让窗帘暂停大约 20px 的滚动,以便在两个块在中间相遇后窗帘不会立即淡出?

4

2 回答 2

0

如果您接受基于库的答案,则有一个很好的解决方案:

skrollr https://github.com/Prinzhorn/skrollr

你可以看到教程解释如何使用这个库来实现你的目标:

ihatetomatoes https://ihatetomatoes.net/create-scrolling-slideshow-using-skrollr/


主要思想是这样的:创建高度为您的主要内容的 100%+20px 的页面,并用 js 转换您的内容位置。当您的滚动在 50%-10px 和 50%+10px 之间时,您可以停止转换主要内容。

于 2016-02-04T17:48:49.057 回答
0

这是一个定时动画中继器的示例。它等待所有动画完成,然后在超时后重复它们。不是 100% 确定这是您的愿望,但希望您可以从中构建:(注意我没有测试此代码,但它应该可以工作。需要 jQuery 作为延迟;

function pullCurtains(){
    $.when(
        $('body,html').animate({'scrollTop': target.offset().top}, 500, function(){ animating = false; }).promise(),
        $( '#mything-2' ).animate( { marginLeft : "-100px" }, 500 ).promise(),
        $( '#mything-3' ).animate( { width: 0 }, 1000 ).promise()
    ).done( function(){
        console.log( "All animations complete." );
        setTimeout(function() {
            // trigger new one in 2000 ms
            $(document).trigger('curtian');
        }, 2000);
    });
};
$(document).on('curtian',function(){
    pullCurtains();
});
// do first one
$(document).trigger('curtian');
于 2016-02-04T19:50:43.703 回答