2012-10-09 76 views
0

我该如何增加滚动循环内的函数?for循环内滚动功能

我:

$(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'); 
}... 

需要进行滚动功能REDY所有的时间内,我对所有的按钮,使相同的块:

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

希望这将使更多感。

回答

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'); 
      } 
     });  
    });  
}); 
+0

因为这是视差,所以它会取消工作,因为滚动会同时滚动所有窗口,如果我在那里滚动,那么窗口中没有内容 – user1709407

0

将这个你.scrollTop()内循环:

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

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