Parallax js活动幻灯片

时间:2014-01-24 09:40:27

标签: javascript jquery parallax

我正在使用parallax prototype,我需要为每张幻灯片指定一个活动的类,以便在特定幻灯片处于活动状态时调用某些函数。

var $window = $(window),
    speed = 0.2;

function update(){ 

    var scrolled = $window.scrollTop(),
        container = $('.container'),
        containerHeight = container.height(),
        updateTop = parseInt(containerHeight) - scrolled * speed;

    $('.js-background-2').css('top', updateTop+'px');
    $('.js-background-2 h2').css('margin-top', (scrolled/2)+'px');

    $('.js-background-3').css('top', (updateTop*2)+'px');
    $('.js-background-3 h2').css('margin-top', (scrolled/3)+'px');

    $('.js-background-4').css('top', (updateTop*3)+'px');
    $('.js-background-4 h2').css('margin-top', (scrolled/4)+'px');

}; 

$window.bind('scroll', update);

0 个答案:

没有答案