0

我如何在滚动循环中乘以函数?

我有:

$(window).scroll(function() {
b1Center = $("#block-1").offset().top - ( $(window).height() - divHeight )/2;
b1Bottom = $("#block-1").offset().top - $(window).height()
b1Top = $("#block-1").offset().top + divHeight;
if(getScrollTop() > b1Bottom && getScrollTop() < b1Top){
$("#block-1 .txt").css('marginTop', ( (getScrollTop()) *(1.6)) + 'px');
}...

这需要一直在滚动功能内部,并且我对所有按钮都有相同的块,所以:

http://jsfiddle.net/Dx3hr/27/

希望这会更有意义。

4

2 回答 2

1

尝试这个:

$(document).ready(function(){
    var divHeight = 700;
    $(window).scroll(function() {
        $(".blocks").each(function(){
            var this = $(this),
                Center = $(this).offset().top - ( $(window).height() - divHeight )/2,
                Bottom = $(this).offset().top - $(window).height(),
                Top = $(this).offset().top + divHeight;
            if(getScrollTop() > Bottom && getScrollTop() < Top){
                this.find('.txt').css('marginTop', ( (getScrollTop()) *(1.6)) + 'px');
            } 
        });    
    });    
});  
于 2012-10-09T05:00:46.657 回答
0

把它放在你的 .scrollTop() 循环中:

$('.block').each(function  () {
    var this_block = $(this);
    this_block.whateverFunction(you, want, to, do);
});

确保使用按钮的类而不是 id ...

于 2012-10-09T05:12:11.333 回答